Your SlideShare is downloading. ×
Android Application Development at JFokus 2011
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Android Application Development at JFokus 2011

4,680
views

Published on

Published in: Technology, News & Politics

3 Comments
8 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,680
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
423
Comments
3
Likes
8
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Android Application Development JFokus 2011 Anders Göranssontisdag den 15 februari 2011
  • 2. About You • Android experience • None / Little • Moderate / Experiencedtisdag den 15 februari 2011
  • 3. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 4. Android History • 2005 - Google acquires Android Inc. • 2007 Sep - Mobile patents filed • 2007 Nov - Open Handset Alliance • 2008 Sep - Android 1.0 • 2008 Oct - G1 (HTC Dream)tisdag den 15 februari 2011
  • 5. 2011 - Why Develop for Android?tisdag den 15 februari 2011
  • 6. 2011 - Why Develop for Android? I. Market share. The future is Android!tisdag den 15 februari 2011
  • 7. 2011 - Why Develop for Android? I. Market share. The future is Android!tisdag den 15 februari 2011
  • 8. 2011 - Why Develop for Android? II. Android will be everywhere!tisdag den 15 februari 2011
  • 9. 2011 - Why Develop for Android? III. It’s open source, it’s free and it’s powerfultisdag den 15 februari 2011
  • 10. 2011 - Why Develop for Android? IV. It’s Java!tisdag den 15 februari 2011
  • 11. Android Platformtisdag den 15 februari 2011
  • 12. Android Platform Linux Process • Each process holds Virtual Machine • Application runs in a sandbox • Applications run with distinct system identity • User Id • Isolated from other applications and platform • Android contains an RPC mechanism for IPCtisdag den 15 februari 2011
  • 13. Android Platform Linux Process Default behavior App A Process ASystem starts App Atisdag den 15 februari 2011
  • 14. Android Platform Linux Process Default behavior App A Process ASystem starts System starts App A App B App B Process Btisdag den 15 februari 2011
  • 15. Android Platform Linux Process Configured behavior App A Process ASystem starts App Atisdag den 15 februari 2011
  • 16. Android Platform Linux Process Configured behavior App A App A App B Process ASystem starts System starts App A App Btisdag den 15 februari 2011
  • 17. Android Platform Linux Process Configured behavior - Same Process name - Same User Id - Same signing cert App A App A App B Process ASystem starts System starts App A App Btisdag den 15 februari 2011
  • 18. Android Platform Linux Process Configured behavior App A Process ASystem starts App Atisdag den 15 februari 2011
  • 19. Android Platform Linux Process Configured behavior App A App A Process ASystem starts App starts App A componentstisdag den 15 februari 2011
  • 20. Android Platform Linux Process Configured behavior App A App A App A Process ASystem starts App starts App starts App A components component Process Btisdag den 15 februari 2011
  • 21. Android Platform Linux Process Configured behavior App A App A App A Process A IPCSystem starts App starts App starts App A components component Process Btisdag den 15 februari 2011
  • 22. Android Platform Android and Java • Apache Harmony class libraries • Java 5.0 • Dalvik Virtual Machine • Memory optimizations • One VM per application • .class-files -> .dex-files • 2.2/Froyo+ includes Just In Time-compilation • Register based (not stack based)tisdag den 15 februari 2011
  • 23. Android Platform Building .java .class .dex .jar .apktisdag den 15 februari 2011
  • 24. Android and Java Runtime .dex App Resources Manifest apktisdag den 15 februari 2011
  • 25. Android and Java Runtime .dex App Resources Manifest apk Optimized Dalvik VM Environmenttisdag den 15 februari 2011
  • 26. Android and Java Runtime .dex App Resources Manifest apk Optimized Dalvik VM Environment Linux properties Linux process - Process Id - User Id - Thread modeltisdag den 15 februari 2011
  • 27. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 28. Android Application Application Activity AndroidManifest.xml “Manifest” Activity Broadcast Content Service Receiver Provider Resourcestisdag den 15 februari 2011
  • 29. Android Application Application App descriptor Activity UI AndroidManifest.xml “Manifest” Event Data Activity Background listener provider tasks Media XML ... Broadcast Content Service Receiver Provider Resourcestisdag den 15 februari 2011
  • 30. Android Application Application App descriptor Activity UI AndroidManifest.xml “Manifest” Event Data Activity Background listener provider tasks Media XML ... Broadcast Content Service Receiver Provider Resources = Componenttisdag den 15 februari 2011
  • 31. Android Application Minimum Application Activity AndroidManifest.xml Plain UI application Resourcestisdag den 15 februari 2011
  • 32. Android Application AndroidManifest.xml <manifest>     <uses-permission />     <permission /> Security       <uses-sdk /> Constraints     <uses-configuration />   AndroidManifest.xml     <uses-feature />       <supports-screens />   Activity     <application>         <activity>...</activity>         <service>...</service>         <receiver>...</receiver> Components         <provider>...</provider>     </application> </manifest>tisdag den 15 februari 2011
  • 33. Android Application Application • Base class for global application state <manifest> <application> AndroidManifest.xml Activity • Subclass to define behavior <activity> <service> <receiver> • Accessible from all components <provider> </application> • Started before all components </manifest> Start onCreate() Active onTerminate() Finishtisdag den 15 februari 2011
  • 34. Android Application Application • Notified when device configuration changes while the application is running AndroidManifest.xml Activity • Device configuration • Keyboard open/closed (HW + HW/SW) • User changes global setting • Locale, Font, etc. • Orientation change • MCC/MNC changetisdag den 15 februari 2011
  • 35. Android Application Resources • Multimedia files • Images AndroidManifest.xml • XML -files Activity • Layouts • Animations • Values (strings, dimensions, colors) • Menu-definitions • Preferencestisdag den 15 februari 2011
  • 36. Android Application Resources Resource definitions /res /anim /fade_in.xml AndroidManifest.xml /drawable Activity /layout /values /xml /rawtisdag den 15 februari 2011
  • 37. Android Application Resources Resource definitions /res /anim Bitmaps: *.png, *.jpg Nine-patches: *.9.png AndroidManifest.xml /drawable Shapes: Descriptive drawings commands, *.xml Activity Layers: Multiple drawables compound to one, *.xml /layout States: Select one drawable in a list based on state, e.g. Button, *.xml /values Levels: Select one drawable in a list based on level, e.g. Battery level, *.xml /xml /rawtisdag den 15 februari 2011
  • 38. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /layout_myactivity.xml /values /xml /rawtisdag den 15 februari 2011
  • 39. Android Application Resources Resource definitions /res /anim <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">SpotifySearcher</string> <string name="artist">Artist</string> <string name="search">Search</string> AndroidManifest.xml <string name="search_result">Search result:</string> /drawable </resources> Activity /layout /strings.xml /colors.xml /values /dimens.xml /arrays.xml /xml /rawtisdag den 15 februari 2011
  • 40. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /values /preferences.xml /xml /*.xml /rawtisdag den 15 februari 2011
  • 41. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /values /xml /raw Arbitrary filestisdag den 15 februari 2011
  • 42. Android Application Resources Providing Resources /res public final class R { public static final class attr { } public static final class color { /anim public static final int dark_grey=0x7f040001; public static final int white=0x7f040000; } public static final class dimen { public static final int margin_vertical_default=0x7f050001; AndroidManifest.xml public static final int padding_default=0x7f050000; /drawable public static final int text_size_default=0x7f050002; public static final int text_size_large=0x7f050003; Activity } Pre-compile public static final class drawable { public static final int icon=0x7f020000; } public static final class id { /layout public static final int button_search=0x7f070001; public static final int edit_search_input=0x7f070000; public static final int text_search_result=0x7f070002; } public static final class layout { public static final int activity_search=0x7f030000; /values } public static final int divider_line=0x7f030001; public static final class string { public static final int app_name=0x7f060000; public static final int artist=0x7f060001; public static final int search=0x7f060002; /xml public static final int search_result=0x7f060003; } } /rawtisdag den 15 februari 2011
  • 43. Android Application Resources Providing Resources /res public final class R { R.java public static final class attr { } public static final class color { /anim public static final int dark_grey=0x7f040001; public static final int white=0x7f040000; } public static final class dimen { public static final int margin_vertical_default=0x7f050001; AndroidManifest.xml public static final int padding_default=0x7f050000; /drawable public static final int text_size_default=0x7f050002; public static final int text_size_large=0x7f050003; Activity } Pre-compile public static final class drawable { public static final int icon=0x7f020000; } public static final class id { /layout public static final int button_search=0x7f070001; public static final int edit_search_input=0x7f070000; public static final int text_search_result=0x7f070002; } public static final class layout { public static final int activity_search=0x7f030000; /values } public static final int divider_line=0x7f030001; public static final class string { public static final int app_name=0x7f060000; public static final int artist=0x7f060001; public static final int search=0x7f060002; /xml public static final int search_result=0x7f060003; } } /rawtisdag den 15 februari 2011
  • 44. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 45. UI • Programmatic and Descriptive UI • Declare UI in XML description • Manipulate UI programmatically AndroidManifest.xml • Separate UI presentation from UI behavior Activity Java object <Element> <Element> <Element> Inflate Java Java <Element> object object <Element> Java Java object objecttisdag den 15 februari 2011
  • 46. UI • Programmatic and Descriptive UI • Declare UI in XML description • Manipulate UI programmatically AndroidManifest.xml • Separate UI presentation from UI behavior Activity View Group <ViewGroup> <View> <ViewGroup> Inflate Java View <View> object Group <View> Java Java object objecttisdag den 15 februari 2011
  • 47. UI • Programmatic and Descriptive UI • Declare UI in XML description • Manipulate UI programmatically AndroidManifest.xml • Separate UI presentation from UI behavior Activity View Group <ViewGroup> <View> <ViewGroup> Inflate View View <View> Group <View> View Viewtisdag den 15 februari 2011
  • 48. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayouttisdag den 15 februari 2011
  • 49. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayouttisdag den 15 februari 2011
  • 50. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayouttisdag den 15 februari 2011
  • 51. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayouttisdag den 15 februari 2011
  • 52. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayout Consider Inflating objects is expensive. Use as few elements as possible. Use ‘layoutopt’tisdag den 15 februari 2011
  • 53. UI Layout Example <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="@dimen/padding_default"> <EditText android:id="@+id/edit_search_input" android:layout_width="fill_parent" AndroidManifest.xml android:layout_height="wrap_content" android:hint="@string/artist" /> <Button Activity android:id="@+id/button_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin_vertical_default" android:layout_marginTop="@dimen/margin_vertical_default" android:text="@string/search" /> <include layout="@layout/divider_line" /> <TextView android:layout_width="fill_parent" Linear android:layout_height="wrap_content" Layout android:layout_marginTop="@dimen/margin_vertical_default" android:textSize="@dimen/text_size_default" android:text="@string/search_result"/> <TextView android:id="@+id/text_search_result" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/dark_grey" android:textSize="@dimen/text_size_large"/> Text Text </LinearLayout> EditText Button View Viewtisdag den 15 februari 2011
  • 54. UI Drawing UI • Top-down traversal • Measure • fill_parent, wrap_content, “fix value” AndroidManifest.xml • ActivityLayout • layout_* Linear Layout Text Text EditText Button View Viewtisdag den 15 februari 2011
  • 55. UI Use Resource Separation <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="@dimen/padding_default"> <EditText android:id="@+id/edit_search_input" android:layout_width="fill_parent" android:layout_height="wrap_content" AndroidManifest.xml android:hint="@string/artist" /> <Button android:id="@+id/button_search" Activity android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin_vertical_default" android:layout_marginTop="@dimen/margin_vertical_default" android:text="@string/search" /> <include layout="@layout/divider_line" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/margin_vertical_default" android:textSize="@dimen/text_size_default" android:text="@string/search_result"/> <TextView android:id="@+id/text_search_result" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/dark_grey" android:textSize="@dimen/text_size_large"/> </LinearLayout>tisdag den 15 februari 2011
  • 56. UI Use Resource Separation <?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?> <LinearLayout <resources> xmlns:android="http://schemas.android.com/apk/res/android" colors.xml <color name="white">#ffffff</color> <color name="dark_grey">#222222</color> android:orientation="vertical" android:layout_width="fill_parent" </resources> android:layout_height="fill_parent" android:padding="@dimen/padding_default"> <EditText android:id="@+id/edit_search_input" android:layout_width="fill_parent" android:layout_height="wrap_content" AndroidManifest.xml android:hint="@string/artist" /> <Button android:id="@+id/button_search" Activity android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin_vertical_default" android:layout_marginTop="@dimen/margin_vertical_default" android:text="@string/search" /> <include layout="@layout/divider_line" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/margin_vertical_default" android:textSize="@dimen/text_size_default" android:text="@string/search_result"/> <TextView android:id="@+id/text_search_result" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/dark_grey" android:textSize="@dimen/text_size_large"/> </LinearLayout>tisdag den 15 februari 2011
  • 57. UI Use Resource Separation <?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?> <LinearLayout <resources> xmlns:android="http://schemas.android.com/apk/res/android" colors.xml <color name="white">#ffffff</color> <color name="dark_grey">#222222</color> android:orientation="vertical" android:layout_width="fill_parent" </resources> android:layout_height="fill_parent" android:padding="@dimen/padding_default"> <EditText android:id="@+id/edit_search_input" <?xml version="1.0" encoding="utf-8"?> android:layout_width="fill_parent" <resources> android:layout_height="wrap_content" <dimen name="padding_default">20dp</dimen> AndroidManifest.xml android:hint="@string/artist" /> <Button android:id="@+id/button_search" dimens.xml <dimen name="margin_vertical_default">20dp</dimen> Activity android:layout_width="wrap_content" android:layout_height="wrap_content" <dimen name="text_size_default">15sp</dimen> <dimen name="text_size_large">20sp</dimen> android:layout_marginBottom="@dimen/margin_vertical_default" </resources> android:layout_marginTop="@dimen/margin_vertical_default" android:text="@string/search" /> <include layout="@layout/divider_line" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/margin_vertical_default" android:textSize="@dimen/text_size_default" android:text="@string/search_result"/> <TextView android:id="@+id/text_search_result" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/dark_grey" android:textSize="@dimen/text_size_large"/> </LinearLayout>tisdag den 15 februari 2011
  • 58. UI Use Resource Separation <?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?> <LinearLayout <resources> xmlns:android="http://schemas.android.com/apk/res/android" colors.xml <color name="white">#ffffff</color> <color name="dark_grey">#222222</color> android:orientation="vertical" android:layout_width="fill_parent" </resources> android:layout_height="fill_parent" android:padding="@dimen/padding_default"> <EditText android:id="@+id/edit_search_input" <?xml version="1.0" encoding="utf-8"?> android:layout_width="fill_parent" <resources> android:layout_height="wrap_content" <dimen name="padding_default">20dp</dimen> AndroidManifest.xml android:hint="@string/artist" /> <Button android:id="@+id/button_search" dimens.xml <dimen name="margin_vertical_default">20dp</dimen> Activity android:layout_width="wrap_content" android:layout_height="wrap_content" <dimen name="text_size_default">15sp</dimen> <dimen name="text_size_large">20sp</dimen> android:layout_marginBottom="@dimen/margin_vertical_default" </resources> android:layout_marginTop="@dimen/margin_vertical_default" android:text="@string/search" /> <include layout="@layout/divider_line" /> <TextView <?xml version="1.0" encoding="utf-8"?> android:layout_width="fill_parent" <resources> android:layout_height="wrap_content" <string name="app_name">SpotifySearcher</string> android:layout_marginTop="@dimen/margin_vertical_default" android:textSize="@dimen/text_size_default" strings.xml <string name="artist">Artist</string> <string name="search">Search</string> android:text="@string/search_result"/> <string name="search_result">Search result:</string> <TextView </resources> android:id="@+id/text_search_result" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/dark_grey" android:textSize="@dimen/text_size_large"/> </LinearLayout>tisdag den 15 februari 2011
  • 59. UI Activity • Application component Activity • Subclassed by application • User interface • Typically one full size screen • Inflates UI layouts • Key events • Activity initialization • onCreate()tisdag den 15 februari 2011
  • 60. UI Accessing Resourcespublic class ActivitySearch extends Activity { private EditText editSearch; Activity private TextView textSearchResult; private Button buttonSearch; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); editSearch = (EditText) findViewById(R.id.edit_search_input); AndroidManifest.xml buttonSearch = (Button) findViewById(R.id.button_search); textSearchResult = (TextView) findViewById(R.id.text_search_result); } Activity 1. Inflate layout 2. Access by Idtisdag den 15 februari 2011
  • 61. UI Accessing Resourcespublic class ActivitySearch extends Activity { public final class R { R.java private EditText editSearch; Activity public static final class attr { } private TextView textSearchResult; public static final class color { private Button buttonSearch; public static final int dark_grey=0x7f040001; public static final int white=0x7f040000; /** Called when the activity is first created. */ } @Override public static final class dimen { public void onCreate(Bundle savedInstanceState) { public static final int margin_vertical_default=0x7f050001; super.onCreate(savedInstanceState); public static final int padding_default=0x7f050000; setContentView(R.layout.activity_search); public static final int text_size_default=0x7f050002; public static final int text_size_large=0x7f050003; editSearch = (EditText) findViewById(R.id.edit_search_input); } AndroidManifest.xml buttonSearch = (Button) findViewById(R.id.button_search); public static final class drawable { textSearchResult = (TextView) findViewById(R.id.text_search_result); public static final int icon=0x7f020000; } } Activity public static final class id { public static final int button_search=0x7f070001; public static final int edit_search_input=0x7f070000; public static final int text_search_result=0x7f070002; } public static final class layout { public static final int activity_search=0x7f030000; public static final int divider_line=0x7f030001; 1. Inflate layout } public static final class string { public static final int app_name=0x7f060000; 2. Access by Id public static final int artist=0x7f060001; public static final int search=0x7f060002; public static final int search_result=0x7f060003; } }tisdag den 15 februari 2011
  • 62. UI Lists • Commonly used • Needs to be efficient • Not consume too much memory • Fast scrolling • Android-way of handling lists efficientlytisdag den 15 februari 2011
  • 63. UI Lists The problem Data source List Data 1 UI Element Data 2 ... Problem Requirement Arbitrary data source Abstract mechanism Arbitrary data type Look and feel of each element Dynamic data Update list after insert, edit, remove Lots of data requires a lot of memory Effective cachingtisdag den 15 februari 2011
  • 64. UI Lists API Data source Data 1 Data 2 ... Problem Requirement Arbitrary data source Abstract mechanism Arbitrary data type Look and feel of each element Dynamic data Update list after insert, edit, remove Lots of data requires a lot of memory Effective cachingtisdag den 15 februari 2011
  • 65. UI Lists API Data source Data 1 Data 2 ... <interface> Adapter Problem Requirement Arbitrary data source Abstract mechanism Arbitrary data type Look and feel of each element Dynamic data Update list after insert, edit, remove Lots of data requires a lot of memory Effective cachingtisdag den 15 februari 2011
  • 66. UI Lists API Data source Data 1 Data 2 ... <interface> ... Adapter Problem Requirement Arbitrary data source Abstract mechanism Arbitrary data type Look and feel of each element Dynamic data Update list after insert, edit, remove Lots of data requires a lot of memory Effective cachingtisdag den 15 februari 2011
  • 67. UI Lists API Data source Data 1 Data 2 ... <interface> ... Adapter list_item_layout.xml Problem Requirement Arbitrary data source Abstract mechanism Arbitrary data type Look and feel of each element Dynamic data Update list after insert, edit, remove Lots of data requires a lot of memory Effective cachingtisdag den 15 februari 2011
  • 68. UI Lists API Data source Data 1 list_item_layout.xml Data 2 list_item_layout.xml ... <interface> ... Adapter ... list_item_layout.xml list_item_layout.xml list_item_layout.xml Problem Requirement Arbitrary data source Abstract mechanism Arbitrary data type Look and feel of each element Dynamic data Update list after insert, edit, remove Lots of data requires a lot of memory Effective cachingtisdag den 15 februari 2011
  • 69. UI Lists API AdapterView Data source Data 1 list_item_layout.xml Data 2 list_item_layout.xml ... <interface> ... Adapter ... list_item_layout.xml list_item_layout.xml list_item_layout.xml Problem Requirement Arbitrary data source Abstract mechanism Arbitrary data type Look and feel of each element Dynamic data Update list after insert, edit, remove Lots of data requires a lot of memory Effective cachingtisdag den 15 februari 2011
  • 70. UI Lists API list_layout.xml AdapterView Data source Data 1 list_item_layout.xml Data 2 list_item_layout.xml ... <interface> ... Adapter ... list_item_layout.xml list_item_layout.xml list_item_layout.xml Problem Requirement Arbitrary data source Abstract mechanism Arbitrary data type Look and feel of each element Dynamic data Update list after insert, edit, remove Lots of data requires a lot of memory Effective cachingtisdag den 15 februari 2011
  • 71. UI Lists Adapter <interface> Adapter BaseAdapter Cursor ArrayAdapter SimpleAdapter Adapter SimpleCursor Adaptertisdag den 15 februari 2011
  • 72. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 73. User Experience • Critical for application success • UX • UI design • Employ a good designer • Deliver expected behavior • Master the Activity lifecycle • Responsive • Master the thread handlingtisdag den 15 februari 2011
  • 74. User Experience Activity Lifecycle States Active Foreground Partly Paused obscured Completely Stopped obscuredtisdag den 15 februari 2011
  • 75. User Experience Activity Lifecycle States Active Foreground Partly Paused obscured Active Completely Stopped obscured Activity stacktisdag den 15 februari 2011
  • 76. User Experience Activity Lifecycle States Active Foreground Paused Partly Active obscured Stopped Completely Stopped obscured Activity stacktisdag den 15 februari 2011
  • 77. User Experience Activity Lifecycle States Active Foreground Active Paused Partly Paused obscured Stopped Completely Stopped obscured Activity stacktisdag den 15 februari 2011
  • 78. User Experience Activity Lifecycle Start Active Paused Stopped Finishtisdag den 15 februari 2011
  • 79. User Experience Activity Lifecycle Start • System callbacks Active • Override in subclass Paused Stopped Finishtisdag den 15 februari 2011
  • 80. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass Paused Stopped Finishtisdag den 15 februari 2011
  • 81. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused Stopped Finishtisdag den 15 februari 2011
  • 82. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused onStop() Stopped Finishtisdag den 15 februari 2011
  • 83. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused onStop() Stopped onDestroy() Finishtisdag den 15 februari 2011
  • 84. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused onStop() Stopped onDestroy() Finishtisdag den 15 februari 2011
  • 85. User Experience Activity Lifecycle Start onCreate() onStart() onRestart() onResume() • System callbacks Active • Override in subclass onPause() Paused onStop() Stopped onDestroy() Finishtisdag den 15 februari 2011
  • 86. User Experience Activity Lifecycle Start onCreate() onStart() onRestart() Entire lifetime onResume() - Long lived objects - Create UI Active onPause() Paused onStop() Stopped onDestroy() Finishtisdag den 15 februari 2011
  • 87. User Experience Activity Lifecycle Start onCreate() onStart() onRestart() Visible lifetime onResume() - Visible but possibly not in foreground Active onPause() Paused onStop() Stopped onDestroy() Finishtisdag den 15 februari 2011
  • 88. User Experience Activity Lifecycle Start onCreate() onStart() onRestart() Foreground lifetime onResume() - User interaction - Frequent cycle Active - Example: Device screen sleep onPause() mode - Lightweight code Paused onStop() Stopped onDestroy() Finishtisdag den 15 februari 2011
  • 89. User Experience Activity Activity transition Tip Activity 1 Save state in onPause() Active onPause() I Active onStop() Activity stack Stoppedtisdag den 15 februari 2011
  • 90. User Experience Activity Activity transition Tip Activity 1 Activity 1I Save state in onPause() Active Start onPause() onCreate() onStart() II Active onResume() I Stopped Active onStop() Activity stack Stoppedtisdag den 15 februari 2011
  • 91. User Experience Activity Activity transition Tip Activity 1 Activity 1I Save state in onPause() Active Start Execution path onPause() onCreate() onStart() II Active onResume() I Stopped Active onStop() Activity stack Stoppedtisdag den 15 februari 2011
  • 92. User Experience Activity Lifecycle Extras Start onCreate() onStart() onRestart() onPostCreate() onResume() onPostResume() Active onPause() Paused onStop() Stopped onDestroy() Finishtisdag den 15 februari 2011
  • 93. User Experience Activity Lifecycle Extras Start onCreate() onStart() onRestart() onPostCreate() onResume() onPostResume() Active onPause() System methods. Paused Normally not used by application. onStop() Stopped onDestroy() Finishtisdag den 15 februari 2011
  • 94. User Experience Activity Lifecycle changes • The User navigates away from the Activity • To another Activity • onStop(), onDestroy() if finish() is called • BACK-button (Donʼt override unless well motivated) • onDestroy() • HOME-button • onStop() • Other App in front, e.g. incoming call, onStop() • Screensaver • onPause()tisdag den 15 februari 2011
  • 95. User Experience Activity Tasktisdag den 15 februari 2011
  • 96. User Experience System Cleanup • System can shut down a process at any time due to low available resources • The processes are ranked according to importance • Foreground process • Visible process • Service process • Background process • Empty processtisdag den 15 februari 2011
  • 97. User Experience System Cleanup Process Hierarchy - Activity in the foreground (onResume called) - Service executing platform callback (onCreate, onStartCommand, onDestroy) Foreground - BroadcastReceiver executing platform callbacktisdag den 15 februari 2011
  • 98. User Experience System Cleanup Process Hierarchy - Activity in the foreground (onResume called) - Service executing platform callback (onCreate, onStartCommand, onDestroy) Foreground - BroadcastReceiver executing platform callback - Visible Activity (onPause) - Hosts Service bound to by visible Activity Visibletisdag den 15 februari 2011
  • 99. User Experience System Cleanup Process Hierarchy - Activity in the foreground (onResume called) - Service executing platform callback (onCreate, onStartCommand, onDestroy) Foreground - BroadcastReceiver executing platform callback - Visible Activity (onPause) - Hosts Service bound to by visible Activity Visible - Explicitly started Service (startService) Servicetisdag den 15 februari 2011
  • 100. User Experience System Cleanup Process Hierarchy - Activity in the foreground (onResume called) - Service executing platform callback (onCreate, onStartCommand, onDestroy) Foreground - BroadcastReceiver executing platform callback - Visible Activity (onPause) - Hosts Service bound to by visible Activity Visible - Explicitly started Service (startService) Service - Background Activity (onStop) Backgroundtisdag den 15 februari 2011
  • 101. User Experience System Cleanup Process Hierarchy - Activity in the foreground (onResume called) - Service executing platform callback (onCreate, onStartCommand, onDestroy) Foreground - BroadcastReceiver executing platform callback - Visible Activity (onPause) - Hosts Service bound to by visible Activity Visible - Explicitly started Service (startService) Service - Background Activity (onStop) Background - No active components Emptytisdag den 15 februari 2011
  • 102. User Experience System Cleanup Process Hierarchy - Activity in the foreground (onResume called) - Service executing platform callback (onCreate, onStartCommand, onDestroy) Foreground - BroadcastReceiver executing platform callback - Visible Activity (onPause) - Hosts Service bound to by visible Activity Visible - Explicitly started Service (startService) Service - Background Activity (onStop) Tip! Background Long running tasks in Activity or BroadcastReceiver are best handled in a - No active components Service instead of local Thread. The Empty process is then ranked higher and the risk of interruption is decreased.tisdag den 15 februari 2011
  • 103. User Experience System Cleanup Background Process Problem Foreground MyActivity Some texttisdag den 15 februari 2011
  • 104. User Experience System Cleanup Background Process Problem Foreground Background MyActivity MyActivity Other Some text Activity OtherActivity startstisdag den 15 februari 2011
  • 105. User Experience System Cleanup Background Process Problem Foreground Background Killed MyActivity MyActivity Other Other Activity Activity Some text OtherActivity System shuts down starts MyActivitytisdag den 15 februari 2011
  • 106. User Experience System Cleanup Background Process Problem Foreground Background Killed Foreground MyActivity MyActivity Other Other MyActivity Activity Activity Some text OtherActivity System shuts down User presses starts MyActivity “Back”tisdag den 15 februari 2011
  • 107. User Experience System Cleanup Background Process Solution • Activity.onSaveInstanceState(Bundle) • Called when Activity is destroyed by the system • Not a lifecycle method • Data that should be retrieved is set in a Bundle • put*-methodstisdag den 15 februari 2011
  • 108. User Experience System Cleanup Background Process Solution Foreground Background Killed MyActivity MyActivity Other Other Activity Activity Some text OtherActivity System shuts down starts MyActivitytisdag den 15 februari 2011
  • 109. User Experience System Cleanup Background Process Solution Foreground Background Killed MyActivity MyActivity Other Other Activity Activity Some text OtherActivity System shuts down starts MyActivity @Override protected void onSaveInstanceState(Bundle bundle) {  super.onSaveInstanceState(outState);  bundle.putString(key, “Some Text”); }tisdag den 15 februari 2011
  • 110. User Experience System Cleanup Background Process Solution Foreground Background Killed Foreground MyActivity MyActivity Other Other MyActivity Activity Activity Some text Some text OtherActivity System shuts down User presses starts MyActivity “Back” @Override protected void onSaveInstanceState(Bundle bundle) {  super.onSaveInstanceState(outState);  bundle.putString(key, “Some Text”); }tisdag den 15 februari 2011
  • 111. User Experience System Cleanup Background Process Solution Foreground Background Killed Foreground MyActivity MyActivity Other Other MyActivity Activity Activity Some text Some text OtherActivity System shuts down User presses starts MyActivity “Back” @Override @Override protected void onCreate(Bundle bundle) { protected void onSaveInstanceState(Bundle bundle) {  super.onCreate(bundle);  super.onSaveInstanceState(outState);  String str = bundle.getString(key);  bundle.putString(key, “Some Text”); ... } }tisdag den 15 februari 2011
  • 112. User Experience Master the thread model • Each application runs in one Linux process by default • Single-threaded model - Main / UI thread • All components and system calls run in the UI thread. • Blocking the UI thread blocks all components • UI toolkit not thread-safe • All UI operations must be made on the UI threadtisdag den 15 februari 2011
  • 113. User Experience Master the thread model Application Not Respondingtisdag den 15 februari 2011
  • 114. User Experience Master the thread model Thread Model Process Atisdag den 15 februari 2011
  • 115. User Experience Master the thread model Thread Model App A Process ASystem starts App Atisdag den 15 februari 2011
  • 116. User Experience Master the thread model Thread Model App A App A Process A UI threadSystem starts App starts App A componentstisdag den 15 februari 2011
  • 117. User Experience Master the thread model Thread Model App A App A App A Process A UI thread UI thread ... Worker threadsSystem starts App starts App starts App A components worker threadstisdag den 15 februari 2011
  • 118. User Experience Master the thread model Thread Model - Blocks the UI thread - Use only lightweight tasks - All UI manipulations ! App A App A App A Process A UI thread UI thread ... Worker threadsSystem starts App starts App starts App A components worker threadstisdag den 15 februari 2011
  • 119. User Experience Master the thread model Thread Model - Blocks the UI thread - Use only lightweight tasks - All UI manipulations ! App A App A App A Process A UI thread UI thread ... Worker threadsSystem starts App starts App starts App A components worker threads - Time consuming tasks - No UI manipulations !tisdag den 15 februari 2011
  • 120. User Experience Master the thread model Thread Handler API 1. Activity.runOnUiThread(Runnable) 2. View.post(Runnable) 3. Handler public class MyActivity extends Activity { private TextView textView;     private void startLongRunningOperation() { new Thread(new Runnable() {     public void run() {       results = doSomethingExpensive();       runOnUiThread(new Runnable() {         public void run() {           textView.setText(results);         }       });     }   }).start();     }tisdag den 15 februari 2011
  • 121. User Experience Master the thread model Thread Handler API 1. Activity.runOnUiThread(Runnable) 2. View.post(Runnable) 3. Handler private TextView textView;     private void startLongRunningOperation() { new Thread(new Runnable() {     public void run() {       results = doSomethingExpensive();       textView.post(new Runnable() {         public void run() {           textView.setText(results);         }       });     }   }).start();     }tisdag den 15 februari 2011
  • 122. User Experience Master the thread model Thread Handler API 1. Activity.runOnUiThread(Runnable) public class MyActivity extends Activity { 2. View.post(Runnable) private TextView textView; 3. Handler     // Need handler for callbacks to the UI thread     final Handler handler = new Handler();     // Create runnable for posting     final Runnable updateResults = new Runnable() {         public void run() {             // UPDATE UI WITH “results” textView.setText(results);         }     };     private void startLongRunningOperation() {         //Fire off a thread to do some work that we shouldnt do //directly in the UI thread         Thread t = new Thread() {             public void run() {                 results = doSomethingExpensive();                 handler.post(updateResults);             }         };         t.start();     }tisdag den 15 februari 2011
  • 123. User Experience Master the thread model Thread Handler API 1. Activity.runOnUiThread(Runnable) - Possible to update many UI objects 2. View.post(Runnable) - Updates one UI object 3. Handler - Generic mechanism not only UI manipulationtisdag den 15 februari 2011
  • 124. User Experience Master the thread model AsyncTask • Handles thread management • Solves common use case • Code separation • Subclass • Create on the UI threadtisdag den 15 februari 2011
  • 125. User Experience Master the thread model StrictMode • Development API defined added in 2.3/Gingerbread • Define thread policy for whatʼs allowed • Detect: Network access, disk reads/writes • Act: Log, show dialog, crash, dropbox public void onCreate() {          StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()                  .detectDiskReads()                  .detectDiskWrites()                  .detectNetwork()                  .penaltyLog()                  .build());      }  }tisdag den 15 februari 2011
  • 126. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 127. Intent • Android message system • Intent is a declare of need • “What you want to do?” • “I want to lookup a contact record” • “I want to launch this web site” • “Show the order confirmation screen” • Activate components • Activity, Service, BroadcastReceivertisdag den 15 februari 2011
  • 128. Intent Types Explicit Intent App A ComponentA ComponentB Intent ComponentX ComponentC ComponentDtisdag den 15 februari 2011
  • 129. Intent Types Explicit Intent Implicit Intent App A App A ComponentA ComponentB Intent Intent “Aspects of ComponentX need” ComponentC ComponentD App B App C App Ctisdag den 15 februari 2011
  • 130. Intent Types Explicit Intent Implicit Intent App A App A ComponentA ComponentB Intent Intent “Aspects of ? ComponentX need” ComponentC ComponentD App B App C App Ctisdag den 15 februari 2011
  • 131. Intent Types • Explicit intent • Directed to a specific component in the application • Compile-time binding • Implicit intent • Directed to any component that can handle the intent • Run-time bindingtisdag den 15 februari 2011
  • 132. Intent Definition • Component name • Action • Data • Category • Extras • Flagstisdag den 15 februari 2011
  • 133. Intent Definition • Package name + Class name • Component name • Explicit intent • Application internal • Action • Data • Category • Extras • Flagstisdag den 15 februari 2011
  • 134. Intent Definition • Component name • String: Names the action to perform • Action •ACTION_EDIT, ACTION_VIEW, etc. •System defined • Data •Intent class • Category •Application •User defined • Extras •Package name + Action name • Flagstisdag den 15 februari 2011
  • 135. Intent Definition • Component name • Action • URI and/or MIME_TYPE • Data • Specifies the content to act upon • Category • Extras • Flagstisdag den 15 februari 2011
  • 136. Intent Definition • Component name • Action • Data • Kind of component that can handle the • Category intent • CATEGORY_BROWSABLE, etc. • Extras • Flagstisdag den 15 februari 2011
  • 137. Intent Definition • Component name • Action • Data • Category • Key-Value pairs with extra information • Extras • Flagstisdag den 15 februari 2011
  • 138. Intent Definition • Component name • Action • Data • Category • Extras • Typically: Instruct how an Activity should be • Flags launchedtisdag den 15 februari 2011
  • 139. Intent IntentFilter • Implicit intents • Define intents that can be received • IntentFilter defines • Action, Data, Category • AndroidManifest.xml <manifest> <application>   <activity> <intent-filter> <action android:name="android.intent.action.MAIN" />         <category android:name="android.intent.category.LAUNCHER" />       </intent-filter> </activity>   </application> </manifest>tisdag den 15 februari 2011
  • 140. Intent IntentFilter <activity android:name="NotesList" android:label="@string/title_notes_list">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>             <intent-filter>                 <action android:name="android.intent.action.VIEW" />                 <action android:name="android.intent.action.EDIT" />                 <action android:name="android.intent.action.PICK" />                 <category android:name="android.intent.category.DEFAULT" />                 <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />             </intent-filter>             <intent-filter>                 <action android:name="android.intent.action.GET_CONTENT" />                 <category android:name="android.intent.category.DEFAULT" />                 <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />             </intent-filter>         </activity>                 <activity android:name="NoteEditor"                   android:theme="@android:style/Theme.Light"                   android:label="@string/title_note" >             <intent-filter android:label="@string/resolve_edit">                 <action android:name="android.intent.action.VIEW" />                 <action android:name="android.intent.action.EDIT" />                 <action android:name="com.android.notepad.action.EDIT_NOTE" />                 <category android:name="android.intent.category.DEFAULT" />                 <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />             </intent-filter>             <intent-filter>                 <action android:name="android.intent.action.INSERT" />                 <category android:name="android.intent.category.DEFAULT" />                 <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />             </intent-filter>         </activity>tisdag den 15 februari 2011
  • 141. Intent Intent Overviewtisdag den 15 februari 2011
  • 142. Intent Intent Overview App App App ActivityA Android Component Manifest IntentFiltertisdag den 15 februari 2011
  • 143. Intent Intent Overview App App App ActivityA Android Component Manifest IntentFilter 1. Install IntentFiltertisdag den 15 februari 2011
  • 144. Intent Intent Overview App A App App App Intent Component (Component) Action ActivityA Android Data Component Manifest Category Extras Flags IntentFilter 1. Install IntentFiltertisdag den 15 februari 2011
  • 145. Intent Intent Overview App A App App App Intent Component (Component) Action ActivityA Android Data Component Manifest Category Extras Flags IntentFilter 2. Send Intent 1. Install Intent Action Data IntentFilter Categorytisdag den 15 februari 2011
  • 146. Intent Intent Overview App A App App App Intent Component (Component) Action ActivityA Android Data Component Manifest Category Extras Flags IntentFilter 2. Send Intent 1. Install Intent Action Data IntentFilter Category 3. Intent resolutiontisdag den 15 februari 2011
  • 147. Intent Intent Overview App A App App App Intent Component (Component) Action ActivityA Android Data Component Manifest Category Extras Flags IntentFilter 2. Send Intent 1. Install Intent 4. Start component Action Data IntentFilter Category 3. Intent resolutiontisdag den 15 februari 2011
  • 148. Intent Intent Overview App A App App App Intent (Component) 5. Hand over Intent Component Intent Action ActivityA Android Data Action Component Manifest Category Data Extras Extras Flags IntentFilter 2. Send Intent 1. Install Intent 4. Start component Action Data IntentFilter Category 3. Intent resolutiontisdag den 15 februari 2011
  • 149. Intent Intent Resolution • ACTION test (Filter: 1..*) • Pass: 1 IntentFilter-action matches Intent-action • CATEGORY test (Filter: 1..*) • Pass: All Intent-categories matches IntentFilter- categories • DATA test (Filter: 0..*) • Uri + MIME-type • Pass: Intent-data is subset of IntentFilter-datatisdag den 15 februari 2011
  • 150. Intent Best Practices • Only reusable Activities shall specify IntentFilter • Check if intent can be handled • Pre-check • PackageManager.queryIntentActivities() • Post-check • Catch exception from startActivity()tisdag den 15 februari 2011
  • 151. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 152. Content Provider - Data Storage • File system • Internal storage & SD Card • SharedPreferences • Key/Value pairs • SQLite DBtisdag den 15 februari 2011
  • 153. ContentProvider SQLite • Relational database • Self-contained • Transactional • No need for separate server process • Stored as a file • /data/data/com.yourdomain.yourAppPackage/databasestisdag den 15 februari 2011
  • 154. ContentProvider Android SQLite API • SQLiteDataBase • SQLiteOpenHelper • ContentValues • Cursor • Container for a query result _id C1 C2 Cursor cur = db.query("tbl_countries", null, null, null, null, null, null); cur.moveToFirst(); while (cur.isAfterLast() == false) { //Do something cur.moveToNext(); } cur.close();tisdag den 15 februari 2011
  • 155. ContentProvider ContentProvider • Generic data handling mechanism for any content type • Store application data • Retrieve application data • Share data between applicationstisdag den 15 februari 2011
  • 156. ContentProvider Motivation - Bookmark example Browser A Store/Retrieve bookmarks DB Atisdag den 15 februari 2011
  • 157. ContentProvider Motivation - Bookmark example Browser A Browser B Store/Retrieve Store/Retrieve bookmarks bookmarks DB A DB Btisdag den 15 februari 2011
  • 158. ContentProvider Motivation - Bookmark example Browser A Browser B Browser C Store/Retrieve Store/Retrieve Store/Retrieve bookmarks bookmarks bookmarks DB A DB B DB Ctisdag den 15 februari 2011
  • 159. ContentProvider Motivation - Bookmark example Browser A Browser B Be a good Android citizen Use native content providers when working with system defined content!tisdag den 15 februari 2011
  • 160. ContentProvider Motivation - Bookmark example Browser A Browser B Be a good Android citizen Use native content providers when working with system defined content!tisdag den 15 februari 2011
  • 161. ContentProvider Motivation - Bookmark example Browser A Browser B Bookmark Be a good Android citizen Content Provider Use native content providers when working with system defined content!tisdag den 15 februari 2011
  • 162. ContentProvider Motivation - Bookmark example Browser A Browser B Store/Retrieve bookmarks Bookmark Be a good Android citizen Content Provider Use native content providers when working with system defined content!tisdag den 15 februari 2011
  • 163. ContentProvider Motivation - Bookmark example Browser A Browser B Store/Retrieve bookmarks Bookmark Be a good Android citizen Content Provider Use native content providers when working with system defined content!tisdag den 15 februari 2011 ?
  • 164. ContentProvider Motivation - Bookmark example Browser A Browser B Browser C Store/Retrieve bookmarks DB C Bookmark Be a good Android citizen Content Provider Use native content providers when working with system defined content!tisdag den 15 februari 2011 ?
  • 165. ContentProvider Motivation - Bookmark example Browser A Browser B Browser C Store/Retrieve bookmarks Bookmark Content Provider x DB C Be a good Android citizen Use native content providers when working with system defined content!tisdag den 15 februari 2011 ?
  • 166. ContentProvider Native Content • android.provider.* • Bookmarks • CallLog • Contacts • Dictionary • Media • Audio, Images, Video • Settings • Device domain modeltisdag den 15 februari 2011
  • 167. ContentProvider Fundamentals • Content Provider is based on DB concept, but abstracts storage mechanism • Database storage the normal use case • ContentProviders exposes data outside the application • ContentProviders expose a full CRUD interface • Create, Retrieve, Update, Deletetisdag den 15 februari 2011
  • 168. ContentProvider Fundamentals • Data model = Database table All ContentProviders, Unique, (cmp Primary Key) _IDtisdag den 15 februari 2011
  • 169. ContentProvider Fundamentals • External interface • Uri, Column name, Field type, Mime type Content Provider 2. Column names 1. Uri 3. Field types _ID Name Phone Location Type 1 Steve 123456 Office Mobiletisdag den 15 februari 2011
  • 170. ContentProvider Fundamentals • Native ContentProviders expose URI and Column names as constants, e.g.: • android.provider.Settings.System.CONTENT_URI • android.provider.ContactsContract.Contacts.CONTENT _URI • Native ContentProviders may require permissions, e.g.: • android.permission.READ_CONTACTS • android.permission.WRITE_SETTINGStisdag den 15 februari 2011
  • 171. ContentProvider Querying for Content • Clients interact with a ContentProvider through a ContentResolver ContentResolver cr = getContentResolver(); • Queries are similar to database queries Cursor cursor = cr.query(Uri uri, String[] columns, String where, String [] selectionArgs, String sortOrder)tisdag den 15 februari 2011
  • 172. ContentProvider Manipulating Content • ContentValues used for insert and update • key/value pairs • Insert Uri uri = insert(Uri uri, ContentValues values) • Update int rows = update(Uri uri, ContentValues values, String where, String[] selectionArgs) • Delete int rows = delete(Uri url, String where, String[] selectionArgs)tisdag den 15 februari 2011
  • 173. ContentProvider Cursor Uri Column names _ID Name Phone Content 1 Steve 123456 Provider 2 Bill 654321tisdag den 15 februari 2011
  • 174. ContentProvider Cursor Client App Uri Column names _ID Name Phone Content 1 Steve 123456 Provider 2 Bill 654321tisdag den 15 februari 2011
  • 175. ContentProvider Cursor Client App Content Resolver query(Uri, {Name, Phone}, “Bill”) Uri Column names _ID Name Phone Content 1 Steve 123456 Provider 2 Bill 654321tisdag den 15 februari 2011
  • 176. ContentProvider Cursor Client App Content Resolver query(Uri, {Name, Phone}, “Bill”) Cursor Uri Column names _ID Name Phone Content 1 Steve 123456 Provider 2 Bill 654321tisdag den 15 februari 2011
  • 177. ContentProvider Cursor Client App Content Resolver query(Uri, {Name, Phone}, “Bill”) Cursor “Access result set” Uri Column names _ID Name Phone Content 1 Steve 123456 Provider 2 Bill 654321tisdag den 15 februari 2011
  • 178. ContentProvider Cursor Client App Content Resolver Result set from query query(Uri, {Name, Phone}, “Bill”) Cursor Bill 654321 “Access result set” Uri Column names _ID Name Phone Content 1 Steve 123456 Provider 2 Bill 654321tisdag den 15 februari 2011
  • 179. ContentProvider Cursor • Access result set from query • Connection to the result set that shall be closed • Cursor management can be handled by the platform Cursor cursor = managedQuery(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) • Handles Cursor lifecycle • Unloads at onPause() • Requery at restarttisdag den 15 februari 2011
  • 180. ContentProvider Cursor • Access result set from query • Connection to the result set that shall be closed • Cursor management can be handled by the platform Cursor cursor = managedQuery(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) • Handles Cursor lifecycle • Unloads at onPause() Utilize the platform • Requery at restart If a Cursor is accessed from an Activity always let the platform manage the Cursor for you.tisdag den 15 februari 2011
  • 181. ContentProvider Expose Data - Step 1 • Decide on storage mechanism • File system • Network • Databasetisdag den 15 februari 2011
  • 182. ContentProvider Expose Data - Step 2 • Extend the ContentProvider class onCreate() - Initialize the provider on application start ______________________________________________________________________________ query(Uri, String[], String, String[], String) - Return Cursor-object insert(Uri, ContentValues) - Insert data update(Uri, ContentValues, String, String[]) - Update data delete(Uri, String, String[]) - Delete data ______________________________________________________________________________ getType(Uri) - Return the data MIME typetisdag den 15 februari 2011
  • 183. ContentProvider Expose Data - Step 2 • Extend the ContentProvider class onCreate() - Initialize the provider on application start UI Thread ______________________________________________________________________________ query(Uri, String[], String, String[], String) - Return Cursor-object insert(Uri, ContentValues) - Insert data update(Uri, ContentValues, String, String[]) - Update data delete(Uri, String, String[]) - Delete data ______________________________________________________________________________ getType(Uri) - Return the data MIME typetisdag den 15 februari 2011
  • 184. ContentProvider Expose Data - Step 2 • Extend the ContentProvider class onCreate() - Initialize the provider on application start UI Thread ______________________________________________________________________________ query(Uri, String[], String, String[], String) - Return Cursor-object insert(Uri, ContentValues) - Insert data Thread update(Uri, ContentValues, String, String[]) - Update data safe delete(Uri, String, String[]) - Delete data ______________________________________________________________________________ getType(Uri) - Return the data MIME typetisdag den 15 februari 2011
  • 185. ContentProvider Expose Data - Step 3 • Declare the ContentProvider <manifest> <manifest>     <application>     <application>         <provider android:name="com.jayway.provider.MyProvider"           android:authorities="com.jayway.provider.myprovider"         <provider>...</provider> ...           </provider>     </application>     </application> </manifest> </manifest>tisdag den 15 februari 2011
  • 186. ContentProvider Expose Data - Step 4 • Create ContentProvider definition according to Android standard • CONTENT_URI • Column names • Mime types • vnd.android.cursor.item/vnd.yourcompanyname.contenttype • vnd.android.cursor.dir/vnd.yourcompanyname.contenttypetisdag den 15 februari 2011
  • 187. ContentProvider Expose Data - Example 1. Storage: DB 2. CONTENT_URI 3. ContentProvider Definition 4. ContentProvider 5. UriMatcher 4. AnimalProvider 5.UriMatcher 3.Animal 2. content://se.jayway.animals/animals _ID PICTURE_URI Name Rarity _DATA1.tisdag den 15 februari 2011
  • 188. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 189. BroadcastReceiver • Receive broadcasted events • System and Apps • Subclass • onReceive() • Registration • Static • Dynamic • Context.registerReceiver()tisdag den 15 februari 2011
  • 190. BroadcastReceiver • Receive broadcasted events • System and Apps • Subclass • onReceive() UI Thread • Registration • Static • Dynamic • Context.registerReceiver()tisdag den 15 februari 2011
  • 191. BroadcastReceiver • Receive broadcasted events • System and Apps • Subclass • onReceive() UI Thread • Registration <manifest> <application> • Static <receiver android:name="com.jayway.MyReceiver"/> • Dynamic </application> </manifest> • Context.registerReceiver()tisdag den 15 februari 2011
  • 192. BroadcastReceiver Lifecycle Incoming Start event onReceive() Active Finishtisdag den 15 februari 2011
  • 193. BroadcastReceiver Normal Broadcasts App A Receiver A Event sender App B Application/ Receiver B Systemtisdag den 15 februari 2011
  • 194. BroadcastReceiver Normal Broadcasts App A Receiver A IntentFilter Event sender <receiver android:name=".MyReceiver"> <intent-filter> <action android:name="some.ACTION" /> </intent-filter> </receiver> App B Application/ IntentFilter Receiver B Systemtisdag den 15 februari 2011
  • 195. BroadcastReceiver Normal Broadcasts App A Receiver A IntentFilter Event sender Intent <receiver android:name=".MyReceiver"> <intent-filter> <action android:name="some.ACTION" /> some.ACTION </intent-filter> </receiver> App B Application/ IntentFilter Receiver B Systemtisdag den 15 februari 2011
  • 196. BroadcastReceiver Normal Broadcasts App A Receiver A IntentFilter Event sender Intent <receiver android:name=".MyReceiver"> <intent-filter> <action android:name="some.ACTION" /> some.ACTION </intent-filter> </receiver> Context.sendBroadcast() App B Application/ IntentFilter Receiver B Systemtisdag den 15 februari 2011
  • 197. BroadcastReceiver Normal Broadcasts App A Receiver A IntentFilter Event sender Intent <receiver android:name=".MyReceiver"> <intent-filter> <action android:name="some.ACTION" /> some.ACTION </intent-filter> </receiver> Context.sendBroadcast() App B Application/ IntentFilter Receiver B Systemtisdag den 15 februari 2011
  • 198. BroadcastReceiver Normal Broadcasts App A Receiver A IntentFilter Event sender Match! Intent <receiver android:name=".MyReceiver"> <intent-filter> <action android:name="some.ACTION" /> some.ACTION </intent-filter> </receiver> Context.sendBroadcast() Match! App B Application/ IntentFilter Receiver B Systemtisdag den 15 februari 2011
  • 199. BroadcastReceiver Normal Broadcasts App A Receiver A IntentFilter Event sender ? Intent <receiver android:name=".MyReceiver"> <intent-filter> <action android:name="some.ACTION" /> some.ACTION </intent-filter> </receiver> Context.sendBroadcast() App B Application/ IntentFilter Receiver B Systemtisdag den 15 februari 2011
  • 200. BroadcastReceiver Normal Broadcasts App A Receiver A IntentFilter Event sender ? Intent <receiver android:name=".MyReceiver"> Undefined <intent-filter> <action android:name="some.ACTION" /> some.ACTION </intent-filter> </receiver> Context.sendBroadcast() App B Application/ IntentFilter Receiver B Systemtisdag den 15 februari 2011
  • 201. BroadcastReceiver Ordered Broadcasts App A Receiver A Event sender App B Application/ Receiver B Systemtisdag den 15 februari 2011
  • 202. BroadcastReceiver Ordered Broadcasts App A Receiver A IntentFilter priority = 1 Event sender <receiver android:name=".MyReceiver"> <intent-filter android:priority=”...”> <action android:name="some.ACTION" /> </intent-filter> App B Application/ IntentFilter Receiver B System priority = 2tisdag den 15 februari 2011
  • 203. BroadcastReceiver Ordered Broadcasts App A Receiver A IntentFilter priority = 1 Event sender Intent <receiver android:name=".MyReceiver"> <intent-filter android:priority=”...”> some.ACTION <action android:name="some.ACTION" /> </intent-filter> App B Application/ IntentFilter Receiver B System priority = 2tisdag den 15 februari 2011
  • 204. BroadcastReceiver Ordered Broadcasts App A Receiver A IntentFilter priority = 1 Event sender Intent <receiver android:name=".MyReceiver"> <intent-filter android:priority=”...”> some.ACTION <action android:name="some.ACTION" /> </intent-filter> Context.sendOrderedBroadcast() App B Application/ IntentFilter Receiver B System priority = 2tisdag den 15 februari 2011
  • 205. BroadcastReceiver Ordered Broadcasts App A Receiver A IntentFilter priority = 1 Event sender Intent <receiver android:name=".MyReceiver"> <intent-filter android:priority=”...”> some.ACTION <action android:name="some.ACTION" /> </intent-filter> Context.sendOrderedBroadcast() App B Application/ IntentFilter Receiver B System priority = 2tisdag den 15 februari 2011
  • 206. BroadcastReceiver Ordered Broadcasts App A Receiver A IntentFilter priority = 1 Event sender Match! Intent <receiver android:name=".MyReceiver"> <intent-filter android:priority=”...”> some.ACTION <action android:name="some.ACTION" /> </intent-filter> Context.sendOrderedBroadcast() Match! App B Application/ IntentFilter Receiver B System priority = 2tisdag den 15 februari 2011
  • 207. BroadcastReceiver Ordered Broadcasts App A Receiver A IntentFilter priority = 1 Event sender ? Intent <receiver android:name=".MyReceiver"> <intent-filter android:priority=”...”> some.ACTION <action android:name="some.ACTION" /> </intent-filter> Context.sendOrderedBroadcast() App B Application/ IntentFilter Receiver B System priority = 2tisdag den 15 februari 2011
  • 208. BroadcastReceiver Ordered Broadcasts App A Receiver A IntentFilter priority = 1 Event sender ? <receiver android:name=".MyReceiver"> <intent-filter android:priority=”...”> <action android:name="some.ACTION" /> </intent-filter> Context.sendOrderedBroadcast() App B Intent Application/ IntentFilter Receiver B some.ACTION System priority = 2tisdag den 15 februari 2011
  • 209. BroadcastReceiver Ordered Broadcasts Event sender AppA App B App C Intent Receiver A Receiver B Receiver C IntentFilter IntentFilter IntentFilter priority = 10 priority = 5 priority = 0 Context.sendOrderedBroadcast()tisdag den 15 februari 2011
  • 210. BroadcastReceiver Ordered Broadcasts Event sender AppA App B App C Receiver A Intent Receiver B Receiver C IntentFilter IntentFilter IntentFilter priority = 10 priority = 5 priority = 0 Context.sendOrderedBroadcast()tisdag den 15 februari 2011
  • 211. BroadcastReceiver Ordered Broadcasts Event sender AppA App B App C Receiver A Receiver B Intent Receiver C IntentFilter IntentFilter IntentFilter priority = 10 priority = 5 priority = 0 Context.sendOrderedBroadcast()tisdag den 15 februari 2011
  • 212. BroadcastReceiver Ordered Broadcasts Event sender AppA App B App C Receiver A Receiver B Receiver C Intent IntentFilter IntentFilter IntentFilter priority = 10 priority = 5 priority = 0 Context.sendOrderedBroadcast()tisdag den 15 februari 2011
  • 213. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 214. Service • Background operation that isnʼt interacting with the user • Less likely to be shut down by the system • Started explicitly or Bound to • startService • bindService • Expose functionality to other appstisdag den 15 februari 2011
  • 215. Service AndroidMainifest.xml • Must be enabled to be started • Permissions limit access to service • android:process=”processName” • Run service in own service • “:a” -> Private process • “”:A -> Global processtisdag den 15 februari 2011
  • 216. Service Lifecycle Client Start Start onCreate() startService() bindService() onCreate() onStartCommand() onBind() onRebind() Active Active stopService() unbindService() onUnbind() onDestroy() onDestroy() Finish Finishtisdag den 15 februari 2011
  • 217. Service Start Modes • Explicitly started services (startService()) • onStartCommand defines start mode • START_STICKY • START_NOT_STICKY     public int onStartCommand(Intent intent, int flags, int startId) {         return START_STICKY;     }tisdag den 15 februari 2011
  • 218. Service Remote Service • Service that doesnʼt run in the same process as the client application • Communication between Linux processes through IPC • Synchronous calls • Android provides an abstraction mechanism for IPC • AIDLtisdag den 15 februari 2011
  • 219. Service Remote Service Android IPC Abstraction • Service defines the interface in an AIDL-file • Limited data set • Primitives, String, List, Map, CharSequence • Parcelables - Custom classes • aidl: Compiles aidl-files • Implement AIDL interface • Expose the interfacetisdag den 15 februari 2011
  • 220. Service Remote Service Android IPC Abstraction aidl MyRemoteInterface.aidl MyRemoteInterface.javatisdag den 15 februari 2011
  • 221. Service Remote Service Android IPC Abstraction aidl MyRemoteInterface.aidl MyRemoteInterface.java MyRemoteInterface <inherit> Binder Stubtisdag den 15 februari 2011
  • 222. Service System Services • Context.getSystemService() • adb shell service list WINDOW_SERVICE LAYOUT_INFLATER_SERVICE ACTIVITY_SERVICE POWER_SERVICE ALARM_SERVICE NOTIFICATION_SERVICE KEYGUARD_SERVICE LOCATION_SERVICE VIBRATOR_SERVICE CONNECTIVITY_SERVICE WIFI_SERVICEtisdag den 15 februari 2011
  • 223. Service System Services • Context.getSystemService() • adb shell service list WINDOW_SERVICE LAYOUT_INFLATER_SERVICE ACTIVITY_SERVICE POWER_SERVICE ALARM_SERVICE Watch out! NOTIFICATION_SERVICE The system services may be closely KEYGUARD_SERVICE related to the current context. Only use LOCATION_SERVICE it within the current context. VIBRATOR_SERVICE CONNECTIVITY_SERVICE WIFI_SERVICEtisdag den 15 februari 2011
  • 224. Service System Services NotificationManager • Notify the user that something has happened • Put message in status bar • Flash backlight User experience! • Flash LEDʼs Use notifications when informing the • Play sound user of events in the background. Don’t show Activity or Dialog.tisdag den 15 februari 2011
  • 225. Service System Services NotificationManager String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); System service int icon = R.drawable.notification_icon; CharSequence tickerText = "Hello"; long when = System.currentTimeMillis(); Create Notification Notification notification = new Notification(icon, tickerText, when); Context context = getApplicationContext(); CharSequence contentTitle = "My notification"; CharSequence contentText = "Hello World!"; Intent notificationIntent = new Intent(this, MyClass.class); Create Intent to send PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); private static final int HELLO_ID = 1; Let the platform have mNotificationManager.notify(HELLO_ID, notification); the notificationtisdag den 15 februari 2011
  • 226. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 227. Application Design Application Activity “Manifest” Activity Resources Broadcast Content Service Receiver Providertisdag den 15 februari 2011
  • 228. Application design Application ApplicationManife A • Global state • Reference to domain model data • Accessible from all components tisdag den 15 februari 2011
  • 229. Application design Activity • Easily gets fat • Move functionality out of the Activity Base Activity Activity Dialog Router Activity Activity Builder Model POJOtisdag den 15 februari 2011
  • 230. Application design Android MVC Controller Model Viewtisdag den 15 februari 2011
  • 231. Application design Android MVC Controller Model View Vi Ja Vi Ja Vi Ja Vi Ja Vi Jatisdag den 15 februari 2011
  • 232. Application design Android MVC Controller Activity Model View Vi Ja Vi Ja Vi Ja Vi Ja Vi Jatisdag den 15 februari 2011
  • 233. Application design Android MVC Controller Activity Model View Content Vi Ja Provider Vi Ja Vi Ja Vi Ja Vi Jatisdag den 15 februari 2011
  • 234. Application design Android MVC Controller Activity Model View Content Vi Ja Cursor Provider Vi Ja Vi Ja Vi Ja Vi Jatisdag den 15 februari 2011
  • 235. Application design Android MVC Controller Activity Model Cursor binds to content View with ContentObserver Content Vi Ja Cursor Provider Vi Ja Vi Ja Vi Ja Vi Ja ContentObserver.onChange() getContext().getContentResolver().notifyChange()tisdag den 15 februari 2011
  • 236. Application design Android Network MVC Google IO: http://www.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html Book: Programming Android, O’Reillytisdag den 15 februari 2011
  • 237. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 238. Android Fragmentation • Screen size • Screen pixel density • Manufacturers • Sony Ericsson, HTC, Samsung, LG, Motorola, etc. • Keyboard • Touch, QWERTY, 12-key, etc."tisdag den 15 februari 2011
  • 239. Fragmentation Screen Size • Small • Normal • Large • XLarge (2.2/Froyo)tisdag den 15 februari 2011
  • 240. Fragmentation Screen Pixel Density • Low (120dpi) • Medium (160dpi) • High (240dpi) • Extra high (320dpi)tisdag den 15 februari 2011
  • 241. Fragmentation Screen Pixel Density Alt. Resource Framework /res /drawable_ldpi /my_image.png /anim /drawable_mdpi /my_image.png AndroidManifest.xml /drawable Activity /drawable_hdpi /my_image.png /layout /drawable_xhdpi /my_image.png /values /xml /rawtisdag den 15 februari 2011
  • 242. Fragmentation Screen Pixel Density Recommendations • Leave as much as possible to the platform to decide • wrap_content, match_parent • Avoid defining absolute pixel values • “px” • Use pixel dependent values • “dp” • “sp”tisdag den 15 februari 2011
  • 243. Fragmentation Platform versionstisdag den 15 februari 2011
  • 244. Fragmentation Screenstisdag den 15 februari 2011
  • 245. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 246. External Tools • Large Android community • Lotʼs of good, helpful third party toolstisdag den 15 februari 2011
  • 247. External Tools Roboguice • Dependency injection framework for Android • http://code.google.com/p/roboguice/ class RoboWay extends RoboActivity {     @InjectView(R.id.name)             TextView name;     @InjectView(R.id.thumbnail)        ImageView thumbnail;     @InjectResource(R.drawable.icon)   Drawable icon;     @InjectResource(R.string.app_name) String myName;     @Inject                            LocationManager loc; class AndroidWay extends Activity {     public void onCreate(Bundle savedInstanceState) {     TextView name;         super.onCreate(savedInstanceState);     ImageView thumbnail;         setContentView(R.layout.main);     LocationManager loc;         name.setText( "Hello, " + myName );     Drawable icon;     }     String myName; }     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);         name      = (TextView) findViewById(R.id.name);         thumbnail = (ImageView) findViewById(R.id.thumbnail);         loc       = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);         icon      = getResources().getDrawable(R.drawable.icon);         myName    = getString(R.string.app_name);         name.setText( "Hello, " + myName );     } }tisdag den 15 februari 2011
  • 248. External Tools Robolectric • Unit test framework • Runs tests on computer and not on device • Tests are run in the computer JVM • Makes mocking frameworks obsolete • http://pivotal.github.com/robolectric/tisdag den 15 februari 2011
  • 249. External Tools Robotium • Black box functional test framework • Source code access not needed • Write test scenarios spanning over multiple activities • Open source • http://code.google.com/p/robotium/tisdag den 15 februari 2011
  • 250. External Tools Google GSON • Converts Java objects to their JSON representation BagOfPrimitives obj = new BagOfPrimitives(); Gson gson = new Gson(); String json = gson.toJson(obj); • Converts JSON representation to Java objects BagOfPrimitives obj2 = gson.fromJson(json, BagOfPrimitives.class)tisdag den 15 februari 2011
  • 251. External Tools microlog4android • Log4j API • File logging (Internal/SD Card) • http://code.google.com/p/microlog4android/tisdag den 15 februari 2011
  • 252. External Tools Maven • Maven Android Plugin • m2eclipse • http://code.google.com/p/maven-android-plugin/tisdag den 15 februari 2011
  • 253. External Tools Memory Analyzer Tool • Analyzes memory dumps • Find memory leaks • Eclipse plugin • http://www.eclipse.org/mat/tisdag den 15 februari 2011
  • 254. Agenda Android Android Application UI intro User Experience Broadcast Service Content Receiver Provider Intents Application Design Android Android External Market Fragmentation Toolstisdag den 15 februari 2011
  • 255. Android Markettisdag den 15 februari 2011
  • 256. Android Market Market Filters • Restricts what Apps are shown to user in Market • Filter • Device type • Publishing status • Priced status • Native platform • Forward locktisdag den 15 februari 2011
  • 257. Android Market Market Filters • Restricts what Apps are shown to user in Market • Filter • Device type • Publishing status • Priced status • Native platform • Forward locktisdag den 15 februari 2011
  • 258. Android Market Market Filters Device Type AndroidManifest.xml <supports-screens> <uses-configuration> <uses-feature> <uses-library> <uses-sdk>tisdag den 15 februari 2011
  • 259. Android Market Register • One time fee: $25tisdag den 15 februari 2011
  • 260. Android Market Register • One time fee: $25 Merchant Accounttisdag den 15 februari 2011
  • 261. Android Market Upload • APK ( < 50 MB) • Screenshots (2 Required + 6 Optional) • Application Icon (Required) • Promotional video (Optional) • Listing details • Contact information (One of WWW, Mail, Phone)tisdag den 15 februari 2011
  • 262. Android Market Paid Apps Argentina* • Australia • Austria • Belgium • Brazil* • Canada • Denmark • Finland • France • Germany • • • • Hong Kong Ireland Israel* Italy • Transaction fee: 30% • • • Japan Mexico* Netherlands • Pricing • New Zealand • • • Norway Portugal Russia* • SEK: 7 SEK - 1500 SEK • Singapore • Spain • South Korea* • Sweden • Switzerland • Taiwan* • United Kingdom • United Statestisdag den 15 februari 2011
  • 263. Android Market Advertising • AdMob • AdSense content • Add market-url • market://<your_app_url>tisdag den 15 februari 2011
  • 264. Android Market Adverstising AdMob SDK • admob-sdk-android.jar <!-- The applications publisher ID assigned by AdMob --> <meta-data android:value="YOUR_ID_HERE" android:name="ADMOB_PUBLISHER_ID" /> <!-- AdMobActivity definition --> <activity android:name="com.admob.android.ads.AdMobActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configChanges="orientation|keyboard|keyboardHidden" /> <!-- Track Market installs --> <receiver android:name="com.admob.android.ads.analytics.InstallReceiver" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver>tisdag den 15 februari 2011
  • 265. Android Market In-App Billing • Sell content in application • Android Market publisher account • Google Checkout merchant account • No Android API • Android Market handles the transactiontisdag den 15 februari 2011
  • 266. Android Market In-App Billingtisdag den 15 februari 2011
  • 267. Android Market In-app Billing Implementation overview • Market-app exposes API • IMarketBillingService.aidl • Service • Send info to Market-app • BroadcastReceiver • Billing info from Market-app • Response codes • Security-component • Integrity of transactiontisdag den 15 februari 2011
  • 268. Android - What are we waiting for? • 3.0 • Tablet version of Android • New UI • Richer widgets • New application set • Fragments APItisdag den 15 februari 2011
  • 269. Thank you for listening!tisdag den 15 februari 2011

×