Android Mobile Phone Development


Context
Android


Dalvik
Development
Me First
           http://stuff

                           Computer
                             Stuff    data
         ...
Context | Timeline
●   2001: Google starts filing mobile patents
●   2005 July: Google Acquires Android Inc
●   2005 Oct: ...
Context | Open Handset Alliance
                   47 Companies
                   Sprint, T-Mobile,
                   Te...
Context | Market

                                                           T-Mobile recently shared some statistics from...
Context | Criticism
●   Google helps T-Mobile block tethering
●   Not standard C library (Bionic)
●   Portions of SDK not ...
Android | Open Source
Runtime Stack                                      Development Stack



     Apache Harmony: Apache2...
Android | Market
Android | Architecture

    Home        Contacts
                 Map       Phone       Browser        Email




  Telepho...
Dalvik | Background
 ●   Dan Bornstein
 ●   Made for low end machines
     ●   low ram (no disk swap space)
     ●   batte...
Dalvik | Pro/ Con of Approach
● All those Java coders ● James Gosling
● All that tooling        hates you
● Don't have to ...
Dalvik | .dex vs .class
  ● Single constant pool
    for all classes                                120




              ...
Dalvik | Other Languages?

anything that dynamically
reads .class files or
dynamically manipulates Java
binaries won't wor...
Dalvik | Zygote
                  Home
                                                 Every new app isn't a VM cold star...
Dalvik | Sandbox
●   Every app is a process
●   process gets its own
    user id
●   files is sandboxed
●   SQLite DB is
 ...
Dalvik | Application Stack

 Activity
                         Back button
 Manager                 does a pop
           ...
Dev | Get Started
●   Android SDK
    ●   http://developer.android.com/sdk
    ●   local documentation
    ●   tools
●   E...
android.*
Dev | APIs                            dalvik.*                junit.framework
                                  ...
Dev | Manifest.xml
manifest


    application

      activity


           intent-filter
                <action android:n...
Dev | Eclipse Plugin
Log.d(TAG, quot;position : quot; + position);
                Log.d(TAG, quot;selection: quot; + POINTS[position]);

Dev |...
Dev | Emulator
●Select AVD to run
●Set up virtual SD card

●Simulate network and

CPU conditions




    ./emulator -skin ...
Dev | adb
 shiv:~/opt/android-sdk-linux_x86-1.0_r2/tools>./adb devices
 List of devices attached
 emulator-5554       devi...
Dev | Hierarchy Viewer




shiv:~/opt/android-sdk-linux_x86-1.0_r2/tools>./hierarchyviewer
Click on device > Load View Hie...
Dev | Activity Life Cycle
      starting


                  running




   stopped                   paused




         ...
<?xml version=quot;1.0quot; encoding=quot;utf-8quot;?>
                               <LinearLayout
                      ...
Dev | Intents
   Activity1                       Intent                              Activity2

         create(Activity2)...
Dev | Intents & Mashability
                                                          InterTubes

                        ...
Dev | Packaging
   .java                            .class

   .java    javac                   .class      dx

   .java  ...
Dev | apk
shiv:~/play>jar -xvf quot;Scrum Poker.apkquot;
shiv:~/play>tree
.
|-- AndroidManifest.xml
|-- Scrum Poker.apk
|-...
/** Called when the activity is first created. */
                                                       @Override
       ...
Dev | Install Time
                     ●   What happens when you install the
          .dex           software...
       ...
Dev | Good Android Code
  ●   sleep, react quickly, sleep
  ●   avoid allocation

  Address[] addressArray = mgr.findAddre...
Dev | Gotchas
●   I accidentally imported the quot;super Rquot; instead of
    my locally generated R. (2 hours)
●   View ...
Dev | Other Cool Stuff
                   ●   SQLite
                   ●   LocationManager
                   ●   Sensors...
Wrap Up | Google IO
●   3 types of agreements
●   3 Ways to code
●   20 handsets in 2009
●   Oprah moment
●   Donut
    ● ...
Wrap Up | Future                   ●   The user experience
                                       will be inconsistent
●  ...
Wrap Up | Questions?




http://neidetcher.com/android.html
Upcoming SlideShare
Loading in...5
×

Introduction to Android by Demian Neidetcher

6,299

Published on

Demian Neidetcher's presentation to the Denver Open Source Users Group on the Android mobile phone platform. Full details and source code available at http://neidetcher.com/android.html

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

No Downloads
Views
Total Views
6,299
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
396
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Introduction to Android by Demian Neidetcher

  1. 1. Android Mobile Phone Development Context Android Dalvik Development
  2. 2. Me First http://stuff Computer Stuff data Stuff x 10 neidetcher.com/android.html
  3. 3. Context | Timeline ● 2001: Google starts filing mobile patents ● 2005 July: Google Acquires Android Inc ● 2005 Oct: Dan Bornstein joins Google to work on Dalvik ● 2007 Nov: Open Handset Alliance is formed and Android SDK is released ● 2008 Oct: T-Mobile G1 is released ● 2009 Jan: Palm Pre announced ● 2009 Feb: Pay apps available on market ● 2009 Jun: Samsung Android phones in EU ● 2009 Nov: Motorola releasing Android phone ● 2009: Possible Acer, Dell and HP net-books http://www.flickr.com/photos/ram_/1637873367/sizes/l/
  4. 4. Context | Open Handset Alliance 47 Companies Sprint, T-Mobile, Telecom Italia, Vodafone, Intel, Texas Instruments, NVIDIA, Asus, Garmin, HTC, LG, Motorola, Samsung, Sony, Toshiba...
  5. 5. Context | Market T-Mobile recently shared some statistics from the Android Market. Right now, there are about 2,300 applications available, which is under one-tenth the size of the iPhone Apps Store's whopping 25,000+. --InformationWeek March 25, 2009 Job Listing Comparison May 9, 2009 how does Android’s growth simplyhired.com compare to iPhone’s growth dice.com at launch? Our android java best answer: both iPhone indeed.com grew more quickly j2me than the market, but iPhone growth monster.com was much faster than Android. careerbuilder.com --admob.com 0 200 400 600 800 1000 1200 1400 1600
  6. 6. Context | Criticism ● Google helps T-Mobile block tethering ● Not standard C library (Bionic) ● Portions of SDK not open (yet) ● Too many free apps ● Android is Not POSIX ● Dalvik is Not Java http://www.flickr.com/photos/scjohnson/3475073977/
  7. 7. Android | Open Source Runtime Stack Development Stack Apache Harmony: Apache2 QEMU: LGPL JFree Chart: LGPL SQLite: Public Domain WebKit: LGPLv2 JCommon: BSD Android: Apache2 Bionic: BSD Eclipse: EPL Linux: GPLv2
  8. 8. Android | Market
  9. 9. Android | Architecture Home Contacts Map Phone Browser Email Telephony Activity Location Notification Package Core Libraries SQLite WebKit OpenGL bionic Dalvik VM WiFi Driver WiFi Camera Power Display Keypad
  10. 10. Dalvik | Background ● Dan Bornstein ● Made for low end machines ● low ram (no disk swap space) ● battery ● Register based (not stack based) ● Not a JVM ● No JIT (it's on the road map) ● most heavy lifting is in native code ● Does no memory management or threading http://www.flickr.com/photos/fremat/447395038/sizes/l/
  11. 11. Dalvik | Pro/ Con of Approach ● All those Java coders ● James Gosling ● All that tooling hates you ● Don't have to deal ● Sun hates you with Sun and JCP ● Java fragmentation ● Optimize byte-code ● No more write for hardware once run everywhere http://www.flickr.com/photos/catwommn/3374184512/
  12. 12. Dalvik | .dex vs .class ● Single constant pool for all classes 120 Compression 100 ● Uncompressed libs browser app alarm app 80 ● More pointing 60 40 ● More sharing 20 0 uncompressed jar compressed jar uncompressed dex http://retrodev.com/android/dexformat.html http://sites.google.com/site/io/dalvik-vm-internals (handouts)
  13. 13. Dalvik | Other Languages? anything that dynamically reads .class files or dynamically manipulates Java binaries won't work without Android specific tweaks scala works :) http://chneukirchen.org/blog/archive/2009/04/programming-for-android-with-scala.html
  14. 14. Dalvik | Zygote Home Every new app isn't a VM cold start Minimize memory requirements by Application Code sharing what we can Map Zygote Application System Code System Libraries Browser Libraries Application Code Email ●Android creates Zygote at startup ●Zygote loads up system libraries Application Code ●Zygote finds out new app is starting ●Zygote forks process, giving all Dalvik VMs (and apps) access to system libraries
  15. 15. Dalvik | Sandbox ● Every app is a process ● process gets its own user id ● files is sandboxed ● SQLite DB is sandboxed http://www.flickr.com/photos/bauchidgw/2820627227/
  16. 16. Dalvik | Application Stack Activity Back button Manager does a pop on the stack Map Browser Email Low memory killer Home will look at LRU apps to destroy
  17. 17. Dev | Get Started ● Android SDK ● http://developer.android.com/sdk ● local documentation ● tools ● Eclipse plugin ● http://dl-ssl.google.com/android/eclipse/
  18. 18. android.* Dev | APIs dalvik.* junit.framework junit.runner org.apache.http org.json org.w3c.dom java.awt.font java.util.logging java.beans java.util.prefs org.xml.sax java.io java.util.regex org.xmlpull.v1 java.lang java.util.zip org.xmlpull.v1.sax2 java.lang.annotation javax.crypto java.lang.ref javax.microedition.khronos.egl java.lang.reflect javax.microedition.khronos.opengles java.math javax.net java.net javax.security.auth java.nio javax.security.auth.callback java.security javax.security.auth.login java.sql javax.security.auth.x500 java.text javax.security.cert java.util javax.sql java.util.concurrent javax.xml java.util.jar http://developer.android.com/reference/packages.html
  19. 19. Dev | Manifest.xml manifest application activity intent-filter <action android:name=quot;android.intent.action.MAINquot; /> <category android:name=quot;android.intent.category.LAUNCHERquot; /> activity
  20. 20. Dev | Eclipse Plugin
  21. 21. Log.d(TAG, quot;position : quot; + position); Log.d(TAG, quot;selection: quot; + POINTS[position]); Dev | Logging
  22. 22. Dev | Emulator ●Select AVD to run ●Set up virtual SD card ●Simulate network and CPU conditions ./emulator -skin QVGA-L
  23. 23. Dev | adb shiv:~/opt/android-sdk-linux_x86-1.0_r2/tools>./adb devices List of devices attached emulator-5554 device shiv:~/opt/android-sdk-linux_x86-1.0_r2/tools>./adb shell # ls sqlite_stmt_journals # cat /proc/cpuinfo cache Processor : ARM926EJ-S rev 5 (v5l) sdcard etc BogoMIPS : 348.16 init Features : swp half thumb fastmult vfp edsp java init.goldfish.rc CPU implementer : 0x41 init.rc CPU architecture: 5TEJ data system CPU variant : 0x0 proc CPU part : 0x926 sys CPU revision : 5 sbin Cache type : write-through default.prop Cache clean : not required root dev Cache lockdown : not supported Cache format : Harvard
  24. 24. Dev | Hierarchy Viewer shiv:~/opt/android-sdk-linux_x86-1.0_r2/tools>./hierarchyviewer Click on device > Load View Hierarchy
  25. 25. Dev | Activity Life Cycle starting running stopped paused destroyed
  26. 26. <?xml version=quot;1.0quot; encoding=quot;utf-8quot;?> <LinearLayout xmlns:android=quot;http://schemas.android.com/apk/res/androidquot; Dev | View android:orientation=quot;verticalquot; android:layout_width=quot;fill_parentquot; android:layout_height=quot;fill_parentquot; > <TextView android:id=quot;@+id/displayPointsTextViewquot; android:layout_width=quot;fill_parentquot; android:layout_height=quot;wrap_contentquot; android:height=quot;400spquot; android:width=quot;300spquot; android:textColor=quot;#FFFquot; android:gravity=quot;center_horizontal|center_verticalquot; android:textSize=quot;210spquot; /> </LinearLayout> public class DisplayActivity extends Activity { TextView myTextView = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.display); // set value for the text myTextView = (TextView) findViewById( R.id.displayPointsTextView); String points = getIntent().getExtras().getString( ScrumPokerActivity.SELECTED_POINTS); if (points.equals(quot;100quot;)) { myTextView.setTextSize(180); } myTextView.setText(points); } }
  27. 27. Dev | Intents Activity1 Intent Activity2 create(Activity2) putExtra(key, value) startActivity(intent) onCreate getIntent() getExtras.get(key):value
  28. 28. Dev | Intents & Mashability InterTubes wheels down in PST YourApp K, thx, bai classes.dex NarcissisticProxy TzChangeReceiverActivity Location AndroidManifext.xml Manager receiver intent:ACTION_TIMEZONE_CHANGED
  29. 29. Dev | Packaging .java .class .java javac .class dx .java .class .xml aapt classes .xml .dex .png .xml classes .xml .dex .png .apk
  30. 30. Dev | apk shiv:~/play>jar -xvf quot;Scrum Poker.apkquot; shiv:~/play>tree . |-- AndroidManifest.xml |-- Scrum Poker.apk |-- classes.dex |-- res | |-- drawable | | `-- refresh.png | `-- layout | |-- display.xml | `-- main.xml `-- resources.arsc 3 directories, 7 files
  31. 31. /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dev | dexdump setContentView(R.layout.main); displayPointsListView = (ListView) findViewById(R.id.pointsListView); int layoutId = android.R.layout.simple_list_item_1; // populate the list view with an array ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, layoutId, POINTS); displayPointsListView.setAdapter(arrayAdapter); displayPointsListView.setOnItemClickListener(mMessageClickedHandler); Virtual methods - } #0 : (in Lcom/neidetcher/scrumpoker/ScrumPoker;) name : 'onCreate' type : '(Landroid/os/Bundle;)V' access : 0x0001 (PUBLIC) code - shiv:~/play>~/opt/android-sdk-linux_x86-1.0_r2/tools/dexdump -d classes.dex registers : 5 ins : 2 outs : 4 insns size : 47 16-bit code units 000ad8: |[000ad8] com.neidetcher.scrumpoker.ScrumPoker.onCreate:(Landroid/os/Bundle;)V 000ae8: 6f20 0100 4300 |0000: invoke-super {v3, v4}, Landroid/app/Activity;.onCreate:(Landroid/os/Bundle;)V // method@00 000aee: 1401 0100 037f |0003: const v1, #float 174128887730233583002069148843976425472.000000 // #7f030001 000af4: 6e20 1e00 1300 |0006: invoke-virtual {v3, v1}, Lcom/neidetcher/scrumpoker/ScrumPoker;.setContentView:(I)V // met 000afa: 1401 0100 057f |0009: const v1, #float 176787343721803414747876762964537114624.000000 // #7f050001 000b00: 6e20 1c00 1300 |000c: invoke-virtual {v3, v1}, Lcom/neidetcher/scrumpoker/ScrumPoker;.findViewById:(I)Landroid/v 000b06: 0c01 |000f: move-result-object v1 000b08: 1f01 0d00 |0010: check-cast v1, Landroid/widget/ListView; // class@000d 000b0c: 5b31 0d00 |0012: iput-object v1, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myListView:Landroid/widget/List 000b10: 1400 0300 0901 |0014: const v0, #float 0.000000 // #01090003 000b16: 2201 0b00 |0017: new-instance v1, Landroid/widget/ArrayAdapter; // class@000b 000b1a: 5432 0800 |0019: iget-object v2, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.POINTS:[Ljava/lang/String; // f 000b1e: 7040 0700 3120 |001b: invoke-direct {v1, v3, v0, v2}, Landroid/widget/ArrayAdapter;.<init>:(Landroid/content/Con 000b24: 5b31 0c00 |001e: iput-object v1, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myArrayAdapter:Landroid/widget/ 000b28: 5431 0d00 |0020: iget-object v1, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myListView:Landroid/widget/List 000b2c: 5432 0c00 |0022: iget-object v2, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myArrayAdapter:Landroid/widget/ 000b30: 6e20 0800 2100 |0024: invoke-virtual {v1, v2}, Landroid/widget/ListView;.setAdapter:(Landroid/widget/ListAdapter 000b36: 5431 0d00 |0027: iget-object v1, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myListView:Landroid/widget/List 000b3a: 5432 0b00 |0029: iget-object v2, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.mMessageClickedHandler:Landroid field@000b 000b3e: 6e20 0900 2100 |002b: invoke-virtual {v1, v2}, Landroid/widget/ListView;.setOnItemClickListener:(Landroid/widget 000b44: 0e00 |002e: return-void catches : (none) positions :
  32. 32. Dev | Install Time ● What happens when you install the .dex software... ● there is no JIT ● security ● verification of dex files dexopt ● Optimization ● specific to hardware ● inlining ● pruning .odex ● static linking http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.html
  33. 33. Dev | Good Android Code ● sleep, react quickly, sleep ● avoid allocation Address[] addressArray = mgr.findAddresses() for(int ii = 0; ii < addressArray.length; ii++) Address[] addressArray = mgr.findAddresses() for(Address currAddress : addressArray) List<Address> addresses = mgr.findAddresses(); for(Address currAddress : addresses) http://kohlerm.blogspot.com/2009/04/analyzing-memory-usage-off-your-android.html
  34. 34. Dev | Gotchas ● I accidentally imported the quot;super Rquot; instead of my locally generated R. (2 hours) ● View layouts can't be camel cased. (30 minutes) ● The tools directory in the Android SDK needs be set to executable to run and for the Eclipse plug- in to work. (10 minutes) ● If your install didn't work on the phone you see a deceptive green check-mark. (10 minutes) ● Don't put heavy object graphs in putExtra() ● Development upgrade to Cupcake was kludgy for me
  35. 35. Dev | Other Cool Stuff ● SQLite ● LocationManager ● Sensors ● Accelerometer ● Compass ● Telephony ● Blue Tooth ● OpenGL ● Camera ● Media
  36. 36. Wrap Up | Google IO ● 3 types of agreements ● 3 Ways to code ● 20 handsets in 2009 ● Oprah moment ● Donut ● Universal search where universe is phone ● Text to speech ● Gestures/ handwriting recognition http://www.flickr.com/photos/francois/3959737/
  37. 37. Wrap Up | Future ● The user experience will be inconsistent ● Desktop phones ● Hardware might be ● Net-books flaky and clunky ● Televisions? ● IBM PC clone of the ● GPS? mobile market Good for 1 well* drink if Android does not have greater than 50% of the iPhone mobile phone OS Android market by June 1, 2014 All Others ~Demian Neidetcher *where well is water
  38. 38. Wrap Up | Questions? http://neidetcher.com/android.html
  1. A particular slide catching your eye?

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

×