2009 android demian neidetcher

Upload: -

Post on 29-May-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 2009 Android Demian Neidetcher

    1/40

  • 8/9/2019 2009 Android Demian Neidetcher

    2/40

    Me First

    dataStuff

    ComputerStuff

    http://stuff

    x 10

    neidetcher.com/android.html

  • 8/9/2019 2009 Android Demian Neidetcher

    3/40

    Why Android?

  • 8/9/2019 2009 Android Demian Neidetcher

    4/40

    Big Picture

  • 8/9/2019 2009 Android Demian Neidetcher

    5/40

    No Money | iPhone Dominates

    simplyhired.com

    dice.com

    indeed.com

    monster.com

    careerbuilder.com

    0 200 400 600 800 1000 1200 1400 1600

    Job Listing ComparisonMay 9, 2009

    android javaiPhone

    j2me

  • 8/9/2019 2009 Android Demian Neidetcher

    6/40

    No Money | Hackable & Pervasive? Canonical is creating framework to run Android apps

    on Ubuntu (netbook remix?)http://www.engadget.com/2009/05/26/canonical-giving-ubuntu-the-gift-of-android-apps/

    XML VM is porting Android apps to iPhone http://www.xmlvm.org/android/

    ASE to script for and on the phone (Lua, Python) http://code.google.com/p/android-scripting/

    iPhone vs Android Dev Comparisonhttp://greensopinion.blogspot.com/2009/07/android-versus-iphone-development.html

    Garmin Adopts Androidhttp://techgeist.net/2009/06/garmin-officially-adopts-android-ditches-in-house-linux-os/

    Android on a Sony?http://www.engadget.com/2009/06/08/sony-building-android-based-walkman-and-pnd-for-2010-launch/ http://phandroid.com/2009/07/04/sony-ericsson-making-xperia-android-holy-smokes/

    http://www.xmlvm.org/android/http://code.google.com/p/android-scripting/http://www.engadget.com/2009/06/08/sony-building-android-based-walkman-and-pnd-for-2010-launch/http://www.engadget.com/2009/06/08/sony-building-android-based-walkman-and-pnd-for-2010-launch/http://www.engadget.com/2009/06/08/sony-building-android-based-walkman-and-pnd-for-2010-launch/http://code.google.com/p/android-scripting/http://www.xmlvm.org/android/
  • 8/9/2019 2009 Android Demian Neidetcher

    7/40

    Android | 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 Aug: new T-Mobile Android phone

    2009: Possible Acer, Dell and HP net-books

  • 8/9/2019 2009 Android Demian Neidetcher

    8/40

    Android | Open Handset Alliance

    47 Companies

    Sprint, T-Mobile,Telecom Italia,

    Vodafone, Intel, TexasInstruments, NVIDIA,Asus, Garmin, HTC,LG, Motorola,Samsung, Sony,Toshiba...

  • 8/9/2019 2009 Android Demian Neidetcher

    9/40

    Android | MarketAndroid | Market

    http://market.android.com/publish/Home

  • 8/9/2019 2009 Android Demian Neidetcher

    10/40

    Android Built on Linux Not POSIX Custom C library

    (bionic)

    http://source.android.com/download

    Androidis a Linux

    Dalvik VM

    Android has many Dalvik VMsDalvik VM

    Dalvik VM

  • 8/9/2019 2009 Android Demian Neidetcher

    11/40

    Android | Open Source

    Linux: GPLv2

    WebKit: LGPLv2SQLite: Public Domain

    Eclipse: EPL

    QEMU: LGPL

    Bionic: BSDAndroid: Apache2

    Apache Harmony: Apache2

    Development StackRuntime Stack

    JFree Chart: LGPL

    JCommon: BSD

  • 8/9/2019 2009 Android Demian Neidetcher

    12/40

    Android | Architecture

    Dalvik VM

    Core Libraries

    WiFi Driver PowerWiFi Camera Keypad

    WebKit

    WiFi

    OpenGLWebKitSQLite OpenGL bionic

    ActivityTelephony NotificationActivity Location Package

    Contacts

    Telephony

    Home Phone Browser EmailMap

    Display

  • 8/9/2019 2009 Android Demian Neidetcher

    13/40

    Android | 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/

  • 8/9/2019 2009 Android Demian Neidetcher

    14/40

    Dalvik

    Differentbeast

    Not Java

    byte code Not JVM

  • 8/9/2019 2009 Android Demian Neidetcher

    15/40

    Dalvik | Background

    Dan Bornstein joinedGoogle 2005

    Made for low end

    machines low ram (no disk swap

    space) battery

    Register based (notstack based)

    No JIT (it's on the roadmap) http://www.flickr.com/photos/fremat/447395038/sizes/l/

  • 8/9/2019 2009 Android Demian Neidetcher

    16/40

  • 8/9/2019 2009 Android Demian Neidetcher

    17/40

    Dalvik | .dex vs .class

    Single constant poolfor all classes

    Uncompressed More pointing

    More sharing

    http://retrodev.com/android/dexformat.html

    uncompressed jar compressed jar uncompressed dex0

    20

    40

    60

    80

    100

    120

    libsbrowser appalarm app

    http://sites.google.com/site/io/dalvik-vm-internals (handouts)

    Compression

  • 8/9/2019 2009 Android Demian Neidetcher

    18/40

    Dalvik | Other Languages?Dalvik | Other Languages?

    Java FX runs on Android (JavaOne2008)

    Anything that dynamically reads .classfiles or dynamically manipulates Javabinaries won't work without Android

    specific tweaks scala works

    http://www.youtube.com/watch?v=BtUX-GS36o8&feature=related http://www.ibm.com/developerworks/opensource/library/os-eclipse-scala/

    http://www.ibm.com/developerworks/opensource/library/os-eclipse-scala/http://www.ibm.com/developerworks/opensource/library/os-eclipse-scala/
  • 8/9/2019 2009 Android Demian Neidetcher

    19/40

    Dalvik | SandboxDalvik | Sandbox

    Every app is a processEvery app is a process process gets its ownprocess gets its own

    user iduser id files is sandboxedfiles is sandboxed SQLite DB isSQLite DB is

    sandboxedsandboxed (just files(just files

    anyways)anyways)

    http://www.flickr.com/photos/bauchidgw/2820627227/http://www.flickr.com/photos/bauchidgw/2820627227/

  • 8/9/2019 2009 Android Demian Neidetcher

    20/40

    Dalvik | Zygote

    Android creates Zygote at startup Zygote loads up system libraries Zygote finds out new app is starting Zygote forks process, giving all Dalvik VMs

    (and apps) access to system libraries

    Every new app isn't a VM cold startMinimize memory requirements by

    sharing what we can

    SystemLibraries

    Zygote

    Home

    ApplicationCode

    SystemLibrariesSystemLibraries

    ApplicationCode

    ApplicationCode

    ApplicationCode

    Email

    Browser

    Map

  • 8/9/2019 2009 Android Demian Neidetcher

    21/40

    Dalvik | Application Stack

    Home

    Email

    Browser

    Map

    ActivityManager

    Low memory killer will look at LRU apps

    to destroy

    Back buttondoes a popon the stack

  • 8/9/2019 2009 Android Demian Neidetcher

    22/40

    Dev elopment

    It's easy Write code in Java

    Lots of tooling Lots of documentation

  • 8/9/2019 2009 Android Demian Neidetcher

    23/40

    Dev | Books

    Amazon has 7 books total (Jun 14, 2009)

  • 8/9/2019 2009 Android Demian Neidetcher

    24/40

    Dev | Get Started

    Android SDKAndroid SDK http://developer.android.com/sdkhttp://developer.android.com/sdk local documentationlocal documentation toolstools

    Eclipse pluginEclipse plugin http://dl-ssl.google.com/android/eclipse/http://dl-ssl.google.com/android/eclipse/

  • 8/9/2019 2009 Android Demian Neidetcher

    25/40

    Dev | APIshttp://developer.android.com/reference/packages.html

    java.awt.font java.beans java.io java.lang java.lang.annotation java.lang.ref java.lang.reflect java.math java.net java.nio java.security java.sql java.text java.util java.util.concurrent java.util.jar

    junit.framework junit.runnerorg.apache.httporg.jsonorg.w3c.domorg.xml.saxorg.xmlpull.v1org.xmlpull.v1.sax2

    android.*dalvik.*

    java.util.logging java.util.prefs java.util.regex java.util.zip javax.crypto javax.microedition.khronos.egl javax.microedition.khronos.opengles javax.net javax.security.auth javax.security.auth.callback javax.security.auth.login javax.security.auth.x500 javax.security.cert javax.sql javax.xml

    ...but

  • 8/9/2019 2009 Android Demian Neidetcher

    26/40

    Dev | 3 rd Party & Workaround

    SCMXL (Apache State Chart XML project) has a good write-up

    http://commons.apache.org/scxml/usecases/scxml-stopwatch-on-android.html

    You can use 3 rd Party APIs If you need J2SE APIs that

    aren't there then include themfrom Apache Harmony

  • 8/9/2019 2009 Android Demian Neidetcher

    27/40

    Dev | Resource Class

    mk19:~/code/scrumpoker>tree.|-- ...|-- res| |-- drawable| | `-- refresh .png| |-- layout| | |-- display .xml| | `-- main .xml

    | `-- values| `-- str ings .xml`-- src

    `-- ...

    mk19:~/code/scrumpoker>cat src/com/neidetcher/scrumpoker/R.java/* AUTO-GENERATED FILE. DO NOT MODIFY.

    ** This class was automatically generated by the* aapt tool from the resource data it found. It* should not be modified by hand.*/

    package com.neidetcher.scrumpoker;

    public final class R {public static final class attr {}public static final class drawable {

    public static final int refresh =0x7f020000;}public static final class id {

    public static final int displayPointsTextView=0x7f050000;

    public static final int pointsListView=0x7f050001;}public static final class layout {

    public static final int display =0x7f030000;public static final int main =0x7f030001;

    }public static final class string {

    public static final int app_name=0x7f040000;}

    }aapt

  • 8/9/2019 2009 Android Demian Neidetcher

    28/40

    Dev | Activity

  • 8/9/2019 2009 Android Demian Neidetcher

    29/40

    Dev | View

    public class DisplayActivity extends Activity{

    TextView myTextView = null;

    @Overridepublic void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);setContentView(R.layout.display);

    // set value for the textmyTextView = (TextView) findViewById(

    R.id. displayPointsTextView );String points = getIntent().getExtras().getString(

    ScrumPokerActivity.SELECTED_POINTS);if (points.equals("100")){

    myTextView.setTextSize(180);}

    myTextView.setText(points) ;

    }}

  • 8/9/2019 2009 Android Demian Neidetcher

    30/40

    Dev | IntentsActivity1 Intent Activity2

    create(Activity2)

    putExtra(key, value)

    startActivity(intent)

    onCreategetIntent()

    getExtras.get(key):value

    Open Intentshttp://www.openintents.org/en/

  • 8/9/2019 2009 Android Demian Neidetcher

    31/40

    Dev | Intents & Mashability

    TzChangeReceiverActivity

    YourApp

    AndroidManifext.xml

    receiver

    classes.dex

    intent:ACTION_TIMEZONE_CHANGED

    LocationManager

    NarcissisticProxy

    InterTubes

    wheels down in PSTFTW!!!

  • 8/9/2019 2009 Android Demian Neidetcher

    32/40

    Dev | Packaging

    .java

    .java

    .java

    javac

    .class

    .class

    .class

    dx

    classes.dex

    .xml

    .xml

    .png

    aapt

    .xml

    .xml

    .png

    classes.dex

    .apk

  • 8/9/2019 2009 Android Demian Neidetcher

    33/40

    Dev | apk

    shiv:~/play>jar -xvf "Scrum Poker.apk"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

    /** Called when the activity is first created. */@Override

  • 8/9/2019 2009 Android Demian Neidetcher

    34/40

    Dev | dexdumpVirtual methods -

    #0 : (in Lcom/neidetcher/scrumpoker/ScrumPoker;)name : 'onCreate'type : '(Landroid/os/Bundle;)V'access : 0x0001 (PUBLIC)code -registers : 5ins : 2outs : 4insns size : 47 16-bit code units

    000ad8: |[000ad8] com.neidetcher.scrumpoker.ScrumPoker.onCreate:(Landroid/os/Bundle;)V000ae8: 6f20 0100 4300 |0000: invoke-super {v3, v4}, Landroid/app/Activity;.onCreate:(Landroid/os/Bundle;)V // metho000aee: 1401 0100 037f |0003: const v1, #float 174128887730233583002069148843976425472.000000 // #7f030001000af4: 6e20 1e00 1300 |0006: invoke-virtual {v3, v1}, Lcom/neidetcher/scrumpoker/ScrumPoker;.setContentView:(I)V //000afa: 1401 0100 057f |0009: const v1, #float 176787343721803414747876762964537114624.000000 // #7f050001000b00: 6e20 1c00 1300 |000c: invoke-virtual {v3, v1}, Lcom/neidetcher/scrumpoker/ScrumPoker;.findViewById:(I)Landro000b06: 0c01 |000f: move-result-object v1000b08: 1f01 0d00 |0010: check-cast v1, Landroid/widget/ListView; // class@000d000b0c: 5b31 0d00 |0012: iput-object v1, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myListView:Landroid/widget/000b10: 1400 0300 0901 |0014: const v0, #float 0.000000 // #01090003000b16: 2201 0b00 |0017: new-instance v1, Landroid/widget/ArrayAdapter; // class@000b000b1a: 5432 0800 |0019: iget-object v2, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.POINTS:[Ljava/lang/String;000b1e: 7040 0700 3120 |001b: invoke-direct {v1, v3, v0, v2}, Landroid/widget/ArrayAdapter;.:(Landroid/content000b24: 5b31 0c00 |001e: iput-object v1, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myArrayAdapter:Landroid/wid000b28: 5431 0d00 |0020: iget-object v1, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myListView:Landroid/widget/000b2c: 5432 0c00 |0022: iget-object v2, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myArrayAdapter:Landroid/wid000b30: 6e20 0800 2100 |0024: invoke-virtual {v1, v2}, Landroid/widget/ListView;.setAdapter:(Landroid/widget/ListAda000b36: 5431 0d00 |0027: iget-object v1, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.myListView:Landroid/widget/000b3a: 5432 0b00 |0029: iget-object v2, v3, Lcom/neidetcher/scrumpoker/ScrumPoker;.mMessageClickedHandler:Landfield@000b000b3e: 6e20 0900 2100 |002b: invoke-virtual {v1, v2}, Landroid/widget/ListView;.setOnItemClickListener:(Landroid/wi000b44: 0e00 |002e: return-void

    catches : (none)positions :

    @Overridepublic void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);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 arrayArrayAdapter arrayAdapter = new ArrayAdapter(this,

    layoutId, POINTS);displayPointsListView.setAdapter(arrayAdapter);displayPointsListView.setOnItemClickListener(mMessageClickedHandler);

    }

    shiv:~/play>~/opt/android-sdk-linux_x86-1.0_r2/tools/dexdump -d classes.dex

  • 8/9/2019 2009 Android Demian Neidetcher

    35/40

    Dev | Install Time What happens when you install the

    software... there is no JIT security verification of dex files Optimization

    specific to hardware inlining pruning static linking

    http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.html

    .odex

    .dex

    dexopt

  • 8/9/2019 2009 Android Demian Neidetcher

    36/40

    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 addresses = mgr.findAddresses();for(Address currAddress : addresses)

    http://kohlerm.blogspot.com/2009/04/analyzing-memory-usage-off-your-android.html

  • 8/9/2019 2009 Android Demian Neidetcher

    37/40

    Dev | Gotchas

    I accidentally imported the "super R" instead ofmy 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 Eclipseplug-in to work. (10 minutes)

    If your install didn't work on the phone you see adeceptive green check-mark. (10 minutes) Don't put heavy object graphs in putExtra() Development upgrade to Cupcake was kludgy for me

  • 8/9/2019 2009 Android Demian Neidetcher

    38/40

    One More Thing | NDK

    Native Dev Kit C/ C++ Consistent libs Docs, tutorials, code Transparent to user

    http://www.flickr.com/photos/sin_agua/2208439930/

    http://android-developers.blogspot.com/2009/06/introducing-android-15-ndk-release-1.html

  • 8/9/2019 2009 Android Demian Neidetcher

    39/40

    Dev | Eclipse Plugin

    Logging Emulator Hierarchy Viewer ADB

  • 8/9/2019 2009 Android Demian Neidetcher

    40/40

    Questions?http://neidetcher.com/android.htmlhttp://neidetcher.com/android.html