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
2. Me First
http://stuff
Computer
Stuff data
Stuff
x 10
neidetcher.com/android.html
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/
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. 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/
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. 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. 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. 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. 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. 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. 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. 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. Dev | Get Started
● Android SDK
● http://developer.android.com/sdk
● local documentation
● tools
● Eclipse plugin
● http://dl-ssl.google.com/android/eclipse/
22. Dev | Emulator
●Select AVD to run
●Set up virtual SD card
●Simulate network and
CPU conditions
./emulator -skin QVGA-L
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. Dev | Hierarchy Viewer
shiv:~/opt/android-sdk-linux_x86-1.0_r2/tools>./hierarchyviewer
Click on device > Load View Hierarchy
25. Dev | Activity Life Cycle
starting
running
stopped paused
destroyed
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);
}
}
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
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. Dev | Other Cool Stuff
● SQLite
● LocationManager
● Sensors
● Accelerometer
● Compass
● Telephony
● Blue Tooth
● OpenGL
● Camera
● Media
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. 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. Wrap Up | Questions?
http://neidetcher.com/android.html