Professional Documents
Culture Documents
Session Feedback
http://www.speakermeter.com/talks/guide-android/ http://goo.gl/XLLgk
Agenda
Android platform Writing your app Anatomy of an app Building your app Surfacing your Content Hardware Sensors Quality Tools Publishing your app Registering for Android Market Targeting
New Platform/SDK releases Target latest but support older Gracefully degrade functionality
Anatomy of an App
Anatomy of an App
Activity
A single screen with a user interface Independent but work together to form a cohesive whole Possible to invoke from other applications Extends the Activity class
Anatomy of an App
Service
Perform long-running operations in the background Does not provide a user interface Other components can bind/interact Extends the Service class
Anatomy of an App
Content provider
Manages a shared set of application data Consistent interface to retrieve/store data RESTful model CRUD operations Can be backed by different stores e.g. File System, SQLite DB, Web Can expose your data to other applications Can consumer data from other Content Providers e.g. Contacts or Call Log Extend the ContentProvider class
Anatomy of an App
Broadcast receiver
Respond to system wide messages Messages can be initiated by the system or an app 2 type of broadcast: Normal - delivered async to all receivers Ordered - delivered in priority order & can be aborted Can programatically register or statically register via the manifest Should be very light, pass any work onto a Service Extend the BroadcastReceiver class
public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); } else if (resultCode == RESULT_CANCELED) { // Handle cancel } }
public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); } else if (resultCode == RESULT_CANCELED) { // Handle cancel } }
public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); } else if (resultCode == RESULT_CANCELED) { // Handle cancel } }
public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); } else if (resultCode == RESULT_CANCELED) { // Handle cancel } }
public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); } else if (resultCode == RESULT_CANCELED) { // Handle cancel } }
Anatomy of an App
Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest ...> <uses-feature ... /> <uses-permission ... /> <uses-sdk ... /> <application ...> <activity ...> ... </activity> <service ...> ... </service> <provider ...> ... </provider> <receiver ...> ... </receiver> </application> </manifest>
Declare components of your app Declare required features for your app State permissions required by your app State platform versions app is compatible with
Anatomy of an App
Activity lifecycle
Running in a multitasking environment Users switch apps, calls come in, system runs low on memory System invokes callbacks in your app The system will kill your app Be sure to save state!
Anatomy of an App
Activity lifecycle
Activity created
Anatomy of an App
Activity lifecycle
Activity created
onCreate()
onResume()
Activity running
Anatomy of an App
Activity lifecycle
onResume()
Anatomy of an App
Activity lifecycle
onResume()
Anatomy of an App
Activity lifecycle
onResume()
Activity running Activity destroyed Low Memory Return to app Call comes in onPause()
Event driven notifications Optional vibration / audio / LED alert Ticker text / pull down draw with more details Custom expanded view Deep link into your app with a PendingIntent
Event driven notifications Optional vibration / audio / LED alert Ticker text / pull down draw with more details Custom expanded view Deep link into your app with a PendingIntent
Display your app's info on the homescreen Updated regularly App can offer multiple widgets Great way to keep user engaged with your app
Push messages from servers to app Send 'tickles' App doesn't have to be running App has full control over how it responds Efficient, event driven updates Uses existing network channel Minimal battery impact Android 2.2+
UI is a hierarchy of View & ViewGroup Defined programatically or in XML Layout files Platform supplies common palette of widgets Create your own widgets
Resources live in the res folder Qualifiers provide specific resources for different device configuration e.g. layout-land, drawable-hdpi Resources IDs automatically generated in R.java e.g. R.layout.main
More than just multitasking Use background tasks to provide fresh information Use the AlarmManager to schedule updates Use 'inexact repeating' to minimise power consumption Regularly sync content from the web Provide offline availability Great for regularly updated content e.g. news feeds
Back button should always move the user back one logical step Try it in accessible mode! Enable TalkBack in Settings -> Accessibility or download from Market
Tools
1. Download and Install the Android SDK developer.android.com/sdk/index.html 2. Download and Install Eclipse http://eclipse.org 3. Install the Android Development Tools (ADT) Eclipse Plugin http://developer.android.com/sdk/eclipse-adt.html#installing 4. Use SDK & AVD Manager in Eclipse to install the latest Android packages.
Full guide: http://developer.android.com/sdk/installing.html
Register For
Create a developer profile Register at http://market.android.com/publish One time $25 fee No limit to number of apps you can publish Developer Distribution Agreement To sell apps, create a Checkout Merchant Account
Targeting
Only target specific countries Target specific hardware e.g. Telephony or OpenGL ES 2.0
// in AndroidManifest.xml <uses-feature android:name="android.hardware.telephony" android:required="true" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" />
Recap
Android platform Writing your app Anatomy of an app Building your app Surfacing your Content Hardware Sensors Quality Tools Publishing your app Registering for Android Market Targeting
Session Feedback
http://www.speakermeter.com/talks/guide-android/ http://goo.gl/XLLgk