Professional Documents
Culture Documents
Google Android - A Developer's Perspective
Google Android - A Developer's Perspective
beginners to Android.
● Google I/O 2008 – for some kickass presentations which
GTalk H.264
QVGA / HVGA
Telephony Accelerometer
Touchscreen
Compass
GPS
Flash, SVG
Agenda
● An android application deconstructed
983 res/drawable/bubble.png
6121 res/drawable/icon.png
608 res/drawable/shadow.png
4068
864
res/layout/login.xml
res/layout/main.xml Android ≠ Java
924 res/layout/map_of_user.xml
3468 AndroidManifest.xml
1676 resources.arsc
94811 classes.dex
$ head -n 4 AndroidManifest.xml
classes.dex
Networking options
java.net.*
java.nio.*
APis used in twam
Database SQLite
Persistence options
SharedPreferences
Filesystem
Other databases: db4o, berkeleydb, neo4j
● An android application deconstructed
●
Under the hood
● API Building Blocks
libc
Linux process sandboxing
● adb ps
# kill -9 <pid>
# kill -15 <pid>
Threads
● An android application deconstructed
●
API Building Blocks
● Is Android lost in space ?
Activity ( View )
Services
ContentProvider
Intent ( IntentReceiver )
Activities & Views
● Activity = Screen, View = UI widget
● ScrollView
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:textSize=”18sp”
>
DisplayMetrics dm = ...
TextView text = ...
text.setTextSize(
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
18,
dm )
);
Lifecycle of Activities
class Activity ..
# onCreate( Bundle )
# onDestroy()
# onFreeze( Bundle )
# onResume()
# onPause()
Normal lifecycle
Simulate low memory
Low memory lifecycle
Implementation of onFreeze
● #3 Use a Service.
Handler handler =
new Handler();
handler.post( new Runnable() {
// update UI elements
} );
Intents
An intent is an operation.
VIEW_ACTION geo:latitude,longitude
EDIT_ACTION content://contacts/1
startSubActivity( intent, 0 );
Intents
mainIntent.addCategory( "com.raverun.HOMESCREEN" );
PackageManager pm = getPackageManager();
List<ResolveInfo> list =
pm.queryIntentActivities(mainIntent, 0);
Intents
intent.putExtra( Constants.SERVICE_KEY, 9 );
Simple logging
Log.d ( String tag, String msg )
Log.e ( .. )
Log.i ( .. )
Log.v ( .. )
Log.w ( .. )
Services
<service
android:name=”.service.AuthServiceImpl”
android:process=”:remote”>
<intent-filter>
<action
android:name=
”com.raverun.twam.remote.AuthService”/>
</intent-filter>
</service>
Services
Background processes
● No jailbreaking required !
<uses-permission
android:name=
“android.permission.RECEIVE_BOOT_COMPLETED”/>
<receiver
android:name=
“.twam.services.OnBootStartService”/>
<intent-filter>
<action android:name=
“android.intent.action.BOOT_COMPLETED” />
</intent-filter>
</receiver>
ContentProviders
class SQLiteDatabase ..
+ execSQL( String sql ) : void
+ rawSQL( String sql, .. ) : Cursor
● Use ContentProviders for shareable data.
● REST-based
class ContentProvider ..
+ query( Uri, ...) : Cursor
+ insert( Uri, ...) : Uri
+ update( Uri, ...) : int
+ delete( Uri, ...) : int
ContentProviders
● URI examples
content : // browser / bookmarks
content : // contacts / people / 23
content : // com.raverun.twam / posts / 860701076
content : // com.raverun.twam / users / 9742542
● Utilities to process & compare URIs
URL_MATCHER = new UriMatcher( UriMatcher.NO_MATCH );
URL_MATCHER.addURI( TwitterPost.AUTHORITY,"posts/#",
POST_ID );
switch( URL_MATCHER.match(uri) )
{
case POST_ID:
// handle it
ContentProviders
(twam) Query for a user
● http://code.google.com/p/android-positron/
Apache 2.0
● http://code.google.com/p/openintents/
Apache 2.0
● http://androidguys.com/
● http:///www.anddev.org/
Books
●
Is Android lost in space ?
● Would you bet your career on Android ?
● Reasons:
● Performance overheads