Android Ecosystem and Revised v4presenter What s New
Why Mobile?
5B 4B 3B 2B 1B Landlines PCs TVs Bank users Mobiles
225M AOL 180M 135M 90M 45M 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Quarters since launch
225M AOL i-mode 180M 135M 90M 45M 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Quarters since launch
225M AOL i-mode Netscape 180M 135M 90M 45M 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Quarters since launch
225M AOL i-mode Netscape ios 180M 135M 90M 45M 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Quarters since launch
225M AOL i-mode Netscape ios Android 180M 135M 90M 45M 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Data from Asymco: asymco.com Quarters since launch
200,000 150,000 100,000 50,000 0 Feb May Jun Aug Today New activations per day
100,000 75,000 50,000 25,000 0 Feb May Jun Aug Today Apps in Android Market
90 devices 21 manufacturers 50 carriers 49 countries
Android: What s Inside Native code Dalvik virtual machine Android NDK apps JNI Android SDK apps Android app framework Harmony libraries Linux kernel, Android extensions
Android: What s Inside Android app framework Activity Manager Window Manager OpenGL ES Surface Manager Content Providers View System SGL FreeType Package Manager Telephony Manager WebKit SQLite Resource Manager Location Manager Media Framework libc Notification Manager... SSL...
Android: What s Inside Currently, Dalvik classes are produced by compiling & translating code written in the Java language Excellent toolchain support Android SDK app Android manifest resource bundle Dalvik classes Community work is under way on enabling other languages to be first class Android citizens
Android: What s Inside This is mostly done by game developers Pretty well all C/C++ code Relatively manual toolchain support Android NDK app Android manifest resource bundle Dalvik classes libraries & JNI
How a Developer Works 1. Download SDK manager from developer.android.com and use it to install SDK versions. 2. Use the Eclipse plug-in, or just build with ant, or program in C/C++ using the NDK. 3. Use tools like ddms and logcat and traceview. 4. Download system source from source.android.com, use it for reference. 5. Register as a developer for US$25. 6. Upload your app to Android Market. 7. There is no Step 7!
What a Developer sees Activities: Something that s happening on the screen Services: Something important in the background Intents: For launching other Activities & Services Broadcast Receivers: Quickly respond to an event Threads and processes: Familiar Linux model Content Providers: Interprocess database wrappers Manifest: Declaring your app to the world Hardware APIs: Location, Camera, Microphone, Video, Accelerometer, and more
Activity Contains the visual user interface Focused on one endeavor More than one per application One Activity is marked for launch Current Activity can starts the next Extends Activity base class
Activity Example
Activity Lifecycle 3 states: active, paused and stopped System can kill if paused or stopped Managed by 7 protected methods Realizing 3 nested lifetime loops Entire Lifetime Visible Lifetime Foreground Lifetime
Activity Lifecycle Entire Lifetime oncreate() onstart() onrestart() Visible Lifetime Foreground Lifetime onresume() RUNNING onpause() onstop() ondestroy() SHUTDOWN
Service Does not have a visual user interface Runs in the background System attempts to keep it alive Communicate through exposed Interface Run in the main thread of application Spawn another thread to avoid blocking Extends Service base class
Service Example
Service Lifecycle 2 states: active and stopped Runs in foreground Not likely to be killed, but possible Managed by 3 public methods
Service Lifecycle Entire Lifetime Active Lifetime oncreate() onstart() RUNNING ondestroy() SHUTDOWN
Intents Has an optional target, an action, a Mime type, and a category, with optional extra data Launch a specific Activity or Service via target Omit the target and the system will find the Activity or Service to start Activities, Services, and BroadcastReceivers register IntentFilters to say they can handle particular Intents How everything in Android is tied together
Intents Intent launch Back button
Intent
Broadcast Receiver Does not have a visual user interface Runs in the background Reacts to broadcast system messages Example: battery charge status Extends BroadcastReceiver base class Has to complete and exit fast
Broadcast Receiver Example
Broadcast Receiver Lifecycle 1 state: active Runs in background...... but not for long! Not likely to be killed, but possible Managed by 1 public method
Broadcast Receiver Lifecycle onreceive() Active Lifetime RUNNING DONE
Content Providers Makes data available to other apps Typically backed by file system or SQLite Extends ContentProvider base class Examples: Contacts, Phone log, Media files, and more
Content Providers ContentProvider
Threading Semantics are like java.lang.thread There s one special thread that owns the UI. You have to arrange to do any real work on another thread, to keep things from bogging down. Shared mutable state... be careful! Lots of potential for deadlocks and race conditions.
Threading private Handler mhandler = new Handler(); // class variable protected void oncreate(bundle mumble) { // in UI thread scallprogress = (ProgressBar) findviewbyid(r.id.scallprogress); new Thread(new CopyIn()).start(); //... class CopyIn implements Runnable { public void run() { while (calls.movetonext()) { // in background thread print.println(call.cursortojson(calls)); savedcalls += 1; scallprogress.setprogress((int) (savedcalls / denominator)); } mhandler.post(new Runnable() { // send this to UI thread String msg = getstring(r.string.saved) + " " + savedcalls + " " }); + getstring(r.string.calls) + "."; public void run() { } cplabel.settext(msg);
Android Manifest XML file that declares app components: Activities, Services, Intent Filters, Broadcast Receivers Names any libraries to be included Identifies permissions needed Identifies hardware required Identifies framework versions
Other bits & pieces APIs for all the hardware and sensors; location services System intents for telephony and SMS and Maps and so on XML subsystem for doing layouts in multiple resolutions and form factors XML subsystem for encoding strings with bilt-in i18n Utilities for IPC... and much more.
Android Releases May 10: Froyo Oct 09: Eclair Apr 09: Cupcake Sep 09: Donut
Android Releases
Android Directions Performance, performance performance New form factors Framework improvements More languages
Android Market Directions On the Web Bigger Easier to search Easier to buy Easier to track
Why I chose Android Open source (GPL + Apache 2) Low-friction market and side-loading Low barrier to entry; java today, more languages tomorrow Straightforward API, light on abstraction Nice clean unboxed Intent/Activity/Service architecture, with a back button Almost nothing hidden
Thank you! feedback: bit.ly/mgddbr Tim Bray, Developer Advocate twbray@google.com android-developers.blogspot.com @AndroidDev