How Do I Code Thee?
Let Me Count The Ways.
Dan Morrill
Google Developer Relations
What is Android?
The Layer Cake

                                         Applications
                  Home                Contacts      ...
What is Android?
A chunk of code for making phone calls




6   Image by Evi Christodoulou; http://www.flickr.com/search/?q=startac&l=comm&...
A robust network stack and Internet client




7
A Platform for Running Code




8   Image by sludgegulper; http://www.flickr.com/photos/sludgeulper/3441498831/
    Licens...
A Platform for Running Code
• Android has an application platform, true
• But we didn’t create Android in an attempt to “o...
"Give me your compiled, your ARM, your huddled
      bytecodes yearning to run free, the wretched refuse of
     your teem...
Agenda
• Introduce the Three Kinds
• Demonstrate how to use them
• Useful comparisons & statistics
• Future directions



...
Anti-Agenda
• I will not...
     – Teach you how to write apps
     – Rehash stuff that’s covered elsewhere
     – Pass ju...
Three Delicious Flavors
The (current) Three Kinds of Android Code
• Managed Code
• Ajax
• Native Code




14   Images by Sharon Mollerus (http://w...
Dalvik Code
Wait Wait, Hold Up
I Need a Victim
• Interesting but computationally significant
• Efficiently externalizable
• Must make for an interesting ...
How about.... k-means clustering?
• Used to identify clusters in sets of points
• We’ll use a simple 2D version
     – 500...
K-Means Clustering in 2,000 Words




     Source: http://en.wikipedia.org/wiki/K-means_clustering


19
Dalvik Code
Dalvik - Overview
• Dalvik is a virtual machine, similar to the JVM or .Net CLR
• Memory-protected, garbage-collected, & l...
Dalvik - Writing Apps
• Apps run on Dalvik, which provides core framework APIs
• APIs are backed by system infrastructure ...
Dalvik - What Can You Do?
• Rich UIs
• Background services
• Shared components
• Tight integration with system events and ...
Dalvik - What Can’t You Do?
• Not much!
• Dalvik is the primary app platform --
 the crossroads
• That does not necessaril...
Dalvik - Demo
Dalvik - Examples
• Core system apps
• Currently (nearly) all apps on the Android Market




26
Dalvik - Future
• Improved (faster, better) garbage collection
• Just-In-Time compilation
• Optimizations in core librarie...
Ajax (Web) Apps
Ajax - Overview
• Apps are broken up into convenient declarative layouts & code
• JavaScript code mutates the DOM to creat...
Ajax on Android - Overview
• Android’s Browser is based on WebKit + SquirrelFish
• WebKit v528.5, equivalent to Safari 4 b...
Ajax - What Can You Do?
• Old sk00l
     – You can, of course, just build static web page apps




31       Image by Jason...
Ajax - What Can You Do?
• But you can also build dynamic UIs, via DOM or <canvas>
• You can fetch & store data on your ori...
Ajax on Android - What Can’t You Do?
• Android doesn’t currently support HTML5, but does have Gears
• Background processin...
Ajax - Demo
Ajax - Examples
• Google Reader for mobile
• Gmail (web version)
• Many mobile web apps (of various fruit flavors)




35
Ajax - Future
• HTML5 will keep getting better
• Android will continue to include a world-class browser
     – Gears today...
Ajax - What Else Can You Do?
  • Augmented Ajax


   Java              Java                     Java
   Object            ...
Augmented Ajax
• Inject functionality into JavaScript




38    Image by Andres Lueda Lopez; http://www.flickr.com/photos/...
Native Code
Native - Overview
• Launched as a Dalvik application
• Loads a dynamic library (.so, ARM ELF, linked against Bionic)
• Mak...
Native - What Can You Do?
• Physics simulations
• Efficient/fast loading of large-ish data files
• Speed-intensive lookups...
Native - What Can’t You Do?
• Current set of APIs is limited to libm and libc
• More will be added over time
• h@x0r the s...
Native - Demo
Native - Examples
• SCUMMVM
• Spotify
• Much of the system, actually...




44
Native - Future
• Add additional libraries, but which? TBD.
  – Let us know!
• No plans to make native code a fully-indepe...
Bonus Demo
How Do You Choose?
Some Data

                        Rendering    Percent
     Modality   Total     Time      Rendering

      Dalvik    614...
Some Data

                        Rendering    Percent
     Modality   Total     Time      Rendering

      Dalvik    614...
Some Data

                        Rendering    Percent
     Modality   Total     Time      Rendering

      Dalvik    614...
What’s that mean?
• Dalvik is very competitive with other pure-interpreted VMs
• Dalvik, as a front-end for native code, u...
Groundbreaking, Dynamo-Interactive Flowchart

    Do you                                       Why not?
   have an        ...
The Bottom Line
• There’s more than one way to do it
• We aren’t out to shove a paradigm down your throat (ouch?)




53  ...
The Bottom Line
• The “centroid” of your app can be anywhere
  – Dalvik apps can embed the web; web apps can call to Dalvi...
And That’s Pretty Much The Long and Short of It




     Source available at: http://code.google.com/p/hdict

55      Imag...
Android : How Do I Code Thee?
Android : How Do I Code Thee?
Upcoming SlideShare
Loading in...5
×

Android : How Do I Code Thee?

3,169

Published on

The material belongs to Google. I do not own it. Copyright infringement is not intended.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,169
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
77
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android : How Do I Code Thee?

  1. 1. How Do I Code Thee? Let Me Count The Ways. Dan Morrill Google Developer Relations
  2. 2. What is Android?
  3. 3. The Layer Cake Applications Home Contacts Phone Browser Application Framework Activity Window Content View Package Telephony Resource Location GTalk Libraries Android Runtime Surface Media SQLite Core OpenGL | FreeType WebKit Dalvik SGL SSL libc Linux Kernel Display Camera Bluetooth Flash Binder USB Keypad WiFi Audio Power 4
  4. 4. What is Android?
  5. 5. A chunk of code for making phone calls 6 Image by Evi Christodoulou; http://www.flickr.com/search/?q=startac&l=comm&ct=0 Licensed under Creative Commons Attribution-Share Alike
  6. 6. A robust network stack and Internet client 7
  7. 7. A Platform for Running Code 8 Image by sludgegulper; http://www.flickr.com/photos/sludgeulper/3441498831/ Licensed under Creative Commons Attribution-Share Alike
  8. 8. A Platform for Running Code • Android has an application platform, true • But we didn’t create Android in an attempt to “own mobile” • Android is a framework for interacting components – Apps can pull in pieces of other apps, the web, or even native 9 Image by genvessel; http://www.flickr.com/photos/genvessel/177133869/ Licensed under Creative Commons Attribution
  9. 9. "Give me your compiled, your ARM, your huddled bytecodes yearning to run free, the wretched refuse of your teeming store. Send these, the threadless, scripted stuff to me, I lift my lamp beside the coder’s door." 10
  10. 10. Agenda • Introduce the Three Kinds • Demonstrate how to use them • Useful comparisons & statistics • Future directions 11
  11. 11. Anti-Agenda • I will not... – Teach you how to write apps – Rehash stuff that’s covered elsewhere – Pass judgment 12
  12. 12. Three Delicious Flavors
  13. 13. The (current) Three Kinds of Android Code • Managed Code • Ajax • Native Code 14 Images by Sharon Mollerus (http://www.flickr.com/photos/clairity/3229586543/) and Gemma Vittoria (http://www.flickr.com/photos/ggvic/3255129747/) Licensed under Creative Commons Attribution
  14. 14. Dalvik Code
  15. 15. Wait Wait, Hold Up
  16. 16. I Need a Victim • Interesting but computationally significant • Efficiently externalizable • Must make for an interesting visualization 17
  17. 17. How about.... k-means clustering? • Used to identify clusters in sets of points • We’ll use a simple 2D version – 500 randomly-generated points – 6 clusters (ROYGBV) • Easy to visualize on screen • 3 implementations – “Pure” Dalvik app (i.e. 100% Java source code) – Same visualization code with C algorithm implementation – JavaScript 18
  18. 18. K-Means Clustering in 2,000 Words Source: http://en.wikipedia.org/wiki/K-means_clustering 19
  19. 19. Dalvik Code
  20. 20. Dalvik - Overview • Dalvik is a virtual machine, similar to the JVM or .Net CLR • Memory-protected, garbage-collected, & lifecycle-managed • Optimized for embedded machines – Built to reduce much of the need for a JITC • Custom bytecode format; included translator from Java bytecode 21 Image by damon brunson; http://www.flickr.com/photos/blackdudemedia/2495758057/ Licensed under Creative Commons Attribution
  21. 21. Dalvik - Writing Apps • Apps run on Dalvik, which provides core framework APIs • APIs are backed by system infrastructure in native code – e.g. OpenGL, Binder IPC, media, etc. • Popular tools are supported, and an Eclipse plugin is available 22
  22. 22. Dalvik - What Can You Do? • Rich UIs • Background services • Shared components • Tight integration with system events and UI • ...but there are other sessions covering standard app dev in detail 23 Image by Jennifer Rensel; http://www.flickr.com/photos/cheesepicklescheese/419050330/ Licensed under Creative Commons Attribution
  23. 23. Dalvik - What Can’t You Do? • Not much! • Dalvik is the primary app platform -- the crossroads • That does not necessarily mean it’s right for your app, though – Some apps need raw speed – Some apps don’t need tight integration 24 Image by Captain DJ; http://www.flickr.com/photos/darrinjonz/117406669/ Licensed under Creative Commons Attribution-Share Alike
  24. 24. Dalvik - Demo
  25. 25. Dalvik - Examples • Core system apps • Currently (nearly) all apps on the Android Market 26
  26. 26. Dalvik - Future • Improved (faster, better) garbage collection • Just-In-Time compilation • Optimizations in core libraries • Additional APIs -- Bluetooth, P2P, and more 27 Image by the Seattle Municipal Archives; http://www.flickr.com/photos/seattlemunicipalarchives/2680241972/ Licensed under Creative Commons Attribution
  27. 27. Ajax (Web) Apps
  28. 28. Ajax - Overview • Apps are broken up into convenient declarative layouts & code • JavaScript code mutates the DOM to create UI effects • Network access is available via XMLHttpRequest • Recently, <canvas> allows JavaScript to do direct painting 29 Image by henrybloomfield; http://www.flickr.com/photos/henrybloomfield/2929756532/ Licensed under Creative Commons Attribution-No Derivative Works
  29. 29. Ajax on Android - Overview • Android’s Browser is based on WebKit + SquirrelFish • WebKit v528.5, equivalent to Safari 4 beta – Reports as 3.1.2 in the user-agent string -- oops! • Includes Gears 0.5.17.0 (including location) • Includes support for the <canvas> tag 30
  30. 30. Ajax - What Can You Do? • Old sk00l – You can, of course, just build static web page apps 31 Image by Jason Rogers; http://www.flickr.com/photos/restlessglobetrotter/434218278/ Licensed under Creative Commons Attribution
  31. 31. Ajax - What Can You Do? • But you can also build dynamic UIs, via DOM or <canvas> • You can fetch & store data on your origin server • With HTML5, you can also: – Access location – Run code outside the main thread – Store data & pages locally 32
  32. 32. Ajax on Android - What Can’t You Do? • Android doesn’t currently support HTML5, but does have Gears • Background processing – Code only runs when Browser is open and your page is loaded • Access system & framework APIs [1] [1] - Hold that thought, though. 33
  33. 33. Ajax - Demo
  34. 34. Ajax - Examples • Google Reader for mobile • Gmail (web version) • Many mobile web apps (of various fruit flavors) 35
  35. 35. Ajax - Future • HTML5 will keep getting better • Android will continue to include a world-class browser – Gears today, HTML5 in the future – Plans to upgrade to an even faster JSVM • Who knows what else? I hear the future is a crazy place 36
  36. 36. Ajax - What Else Can You Do? • Augmented Ajax Java Java Java Object Object Object addJavaScriptInterface Dalvik WebView 37 Image by Luis Villa del Campo; http://www.flickr.com/photos/maguisso/271623867/ Licensed under Creative Commons Attribution
  37. 37. Augmented Ajax • Inject functionality into JavaScript 38 Image by Andres Lueda Lopez; http://www.flickr.com/photos/andresrueda/2983149263/ Licensed under Creative Commons Attribution-No Derivative Works
  38. 38. Native Code
  39. 39. Native - Overview • Launched as a Dalvik application • Loads a dynamic library (.so, ARM ELF, linked against Bionic) • Makes calls into native code via JNI for heavy lifting • .so files are created using the NDK complement to the SDK • Work-in-progress NDK added to donut branch in git 40 Image by Thomas; http://www.flickr.com/photos/tomsaint/2678120228/ Licensed under Creative Commons Attribution
  40. 40. Native - What Can You Do? • Physics simulations • Efficient/fast loading of large-ish data files • Speed-intensive lookups, such as for IMEs • Custom VMs (long live obsolete games!) • Unsupported things... – Technically, other libraries are present, but have no guarantees – Use them, and you deserve the Market user ratings you will get when your app breaks 41
  41. 41. Native - What Can’t You Do? • Current set of APIs is limited to libm and libc • More will be added over time • h@x0r the system -- sandboxing still applies 42
  42. 42. Native - Demo
  43. 43. Native - Examples • SCUMMVM • Spotify • Much of the system, actually... 44
  44. 44. Native - Future • Add additional libraries, but which? TBD. – Let us know! • No plans to make native code a fully-independent app model – ...but there’s no reason to prevent developers from doing stuff 45
  45. 45. Bonus Demo
  46. 46. How Do You Choose?
  47. 47. Some Data Rendering Percent Modality Total Time Rendering Dalvik 614 16 2.6% JavaScript 936 303 32.4% Native 127 15 11.2% 48
  48. 48. Some Data Rendering Percent Modality Total Time Rendering Dalvik 614 16 2.6% JavaScript 936 303 32.4% Native 127 15 11.2% 49
  49. 49. Some Data Rendering Percent Modality Total Time Rendering Dalvik 614 16 2.6% JavaScript 936 303 32.4% Native 127 15 11.2% 50
  50. 50. What’s that mean? • Dalvik is very competitive with other pure-interpreted VMs • Dalvik, as a front-end for native code, usually beats JavaScript – But clearly, there are use cases where that doesn’t matter • And of course, custom native code will always win the speed test 51
  51. 51. Groundbreaking, Dynamo-Interactive Flowchart Do you Why not? have an Is it You should Java existing web Ajax? go make it C/C++ site? Ajaxy. JavaScript Do Haven’t we been you need REST here before? a web Service Hey, site? what Ugh, I languages do you even know? have a Does your app need to be really Seriously, now. Really headache. Okay fine, fast? REALLY Native fast? Augmented Ajax Hmm, hold on. Do Ajax you need tight Yeah, that’s Dalvik integration with what I system? thought. 52
  52. 52. The Bottom Line • There’s more than one way to do it • We aren’t out to shove a paradigm down your throat (ouch?) 53 Image by i_yudai; http://www.flickr.com/photos/y_i/2330044065/ Licensed under Creative Commons Attribution
  53. 53. The Bottom Line • The “centroid” of your app can be anywhere – Dalvik apps can embed the web; web apps can call to Dalvik – Apps can include native code pieces for better performance • Understand your app, & decide based on your app’s needs – If you’re doing lots of drawing, use Dalvik – If you have a web presence already, use (Dalvik-enhanced?) Ajax – If you have large, slow algorithms, use Dalvik + native code – Your skills do mean something: go with what you know! 54
  54. 54. And That’s Pretty Much The Long and Short of It Source available at: http://code.google.com/p/hdict 55 Image by Alexander Henning Drachmann; http://www.flickr.com/photos/drachmann/327122302/ Licensed under Creative Commons Attribution-Share Alike
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×