0
Android Application                         Development                                JFokus 2011                        ...
About You                     •        Android experience                              •   None / Little                  ...
Agenda                                                     Android                              Android               Appl...
Android History                     •        2005 - Google acquires Android Inc.                     •        2007 Sep - M...
2011 - Why Develop for Android?tisdag den 15 februari 2011
2011 - Why Develop for Android?                               I. Market share. The future is Android!tisdag den 15 februar...
2011 - Why Develop for Android?                               I. Market share. The future is Android!tisdag den 15 februar...
2011 - Why Develop for Android?                                 II. Android will be everywhere!tisdag den 15 februari 2011
2011 - Why Develop for Android?                      III. It’s open source, it’s free and it’s powerfultisdag den 15 febru...
2011 - Why Develop for Android?                                         IV. It’s Java!tisdag den 15 februari 2011
Android Platformtisdag den 15 februari 2011
Android Platform                                            Linux Process                     •        Each process holds ...
Android Platform                                  Linux Process    Default behavior                              App A    ...
Android Platform                                  Linux Process    Default behavior                              App A    ...
Android Platform                                  Linux Process    Configured behavior                              App A  ...
Android Platform                                  Linux Process    Configured behavior                              App A  ...
Android Platform                                  Linux Process    Configured behavior                                     ...
Android Platform                                  Linux Process    Configured behavior                              App A  ...
Android Platform                                  Linux Process    Configured behavior                              App A  ...
Android Platform                                  Linux Process    Configured behavior                              App A  ...
Android Platform                                  Linux Process    Configured behavior                              App A  ...
Android Platform                                      Android and Java                      •       Apache Harmony class l...
Android Platform                                      Building                              .java      .class   .dex      ...
Android and Java                                     Runtime                                      .dex                    ...
Android and Java                                     Runtime                                      .dex                    ...
Android and Java                                     Runtime                                      .dex                    ...
Agenda                                                     Android                              Android               Appl...
Android Application                                                    Application                                        ...
Android Application                                                     Application                  App                  ...
Android Application                                                     Application                  App                  ...
Android Application                                              Minimum                                      Application ...
Android Application                                AndroidManifest.xml                              <manifest>            ...
Android Application                                             Application                              •   Base class fo...
Android Application                                               Application                              •              ...
Android Application                               Resources              • Multimedia files              • Images       And...
Android Application                     Resources                                  Resource definitions             /res  ...
Android Application                     Resources                                  Resource definitions             /res  ...
Android Application                     Resources                                  Resource definitions             /res  ...
Android Application                     Resources                                  Resource definitions             /res  ...
Android Application                     Resources                                  Resource definitions             /res  ...
Android Application                     Resources                                  Resource definitions             /res  ...
Android Application                     Resources                                  Providing Resources             /res   ...
Android Application                     Resources                                  Providing Resources             /res   ...
Agenda                                                     Android                              Android               Appl...
UI                  •       Programmatic and Descriptive UI              • Declare UI in XML description              • Ma...
UI                  •       Programmatic and Descriptive UI              • Declare UI in XML description              • Ma...
UI                  •       Programmatic and Descriptive UI              • Declare UI in XML description              • Ma...
UI                                               Layouts                     •        Implements ViewGroup                ...
UI                                               Layouts                     •        Implements ViewGroup                ...
UI                                               Layouts                     •        Implements ViewGroup                ...
UI                                               Layouts                     •        Implements ViewGroup                ...
UI                                                  Layouts                     •        Implements ViewGroup             ...
UI                                            Layout Example                                                          <?xm...
UI                                                   Drawing UI                   •          Top-down traversal           ...
UI                              Use Resource Separation   <?xml version="1.0" encoding="utf-8"?>   <LinearLayout       xml...
UI                              Use Resource Separation   <?xml version="1.0" encoding="utf-8"?>                          ...
UI                              Use Resource Separation   <?xml version="1.0" encoding="utf-8"?>                          ...
UI                              Use Resource Separation   <?xml version="1.0" encoding="utf-8"?>                          ...
UI                                                  Activity                     •        Application component           ...
UI                                  Accessing Resourcespublic class ActivitySearch extends Activity {		    private EditTex...
UI                                  Accessing Resourcespublic class ActivitySearch extends Activity {                     ...
UI                                                   Lists                     •        Commonly used                     ...
UI                     Lists                                 The problem     Data source                                  ...
UI                     Lists                                            API     Data source                 Data 1        ...
UI                     Lists                                            API     Data source                 Data 1        ...
UI                     Lists                                            API     Data source                 Data 1        ...
UI                     Lists                                               API     Data source                 Data 1     ...
UI                     Lists                                            API     Data source                 Data 1        ...
UI                     Lists                                            API                                               ...
UI                     Lists                                            API                                               ...
UI                     Lists                                     Adapter                                      <interface> ...
Agenda                                                     Android                              Android               Appl...
User Experience                 •       Critical for application success                 •       UX                     • ...
User Experience                Activity                                          Lifecycle               States           ...
User Experience                Activity                                          Lifecycle               States           ...
User Experience                Activity                                          Lifecycle               States           ...
User Experience                Activity                                          Lifecycle               States           ...
User Experience               Activity                                         Lifecycle               Start              ...
User Experience               Activity                                         Lifecycle               Start              ...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience               Activity                                         Lifecycle               Start            on...
User Experience                Activity                              Activity transition                                  ...
User Experience                Activity                              Activity transition                                  ...
User Experience                         Activity                                     Activity transition                  ...
User Experience               Activity                              Lifecycle Extras               Start            onCrea...
User Experience               Activity                              Lifecycle Extras               Start            onCrea...
User Experience                           Activity                                       Lifecycle changes                ...
User Experience               Activity                                         Tasktisdag den 15 februari 2011
User Experience                                       System Cleanup                     •        System can shut down a p...
User Experience                            System Cleanup                                      Process Hierarchy          ...
User Experience                             System Cleanup                                       Process Hierarchy        ...
User Experience                              System Cleanup                                        Process Hierarchy      ...
User Experience                              System Cleanup                                        Process Hierarchy      ...
User Experience                              System Cleanup                                        Process Hierarchy      ...
User Experience                              System Cleanup                                        Process Hierarchy      ...
User Experience                    System Cleanup                                 Background Process                      ...
User Experience                           System Cleanup                                   Background Process             ...
User Experience                           System Cleanup                                   Background Process             ...
User Experience                           System Cleanup                                   Background Process             ...
User Experience                          System Cleanup                                      Background Process           ...
User Experience                           System Cleanup                                   Background Process             ...
User Experience                           System Cleanup                                   Background Process             ...
User Experience                           System Cleanup                                   Background Process             ...
User Experience                           System Cleanup                                   Background Process             ...
User Experience                              Master the thread model                     •        Each application runs in...
User Experience               Master the thread model                  Application Not Respondingtisdag den 15 februari 2011
User Experience               Master the thread model                                     Thread Model            Process ...
User Experience               Master the thread model                                     Thread Model                    ...
User Experience               Master the thread model                                     Thread Model                    ...
User Experience               Master the thread model                                     Thread Model                    ...
User Experience               Master the thread model                                     Thread Model                    ...
User Experience               Master the thread model                                     Thread Model                    ...
User Experience               Master the thread model                              Thread Handler API                  1. ...
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
Upcoming SlideShare
Loading in...5
×

Android Application Development at JFokus 2011

4,818

Published on

Published in: Technology, News & Politics
3 Comments
8 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,818
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
424
Comments
3
Likes
8
Embeds 0
No embeds

No notes for slide

Transcript of "Android Application Development at JFokus 2011"

  1. 1. Android Application Development JFokus 2011 Anders Göranssontisdag den 15 februari 2011
  2. 2. About You • Android experience • None / Little • Moderate / Experiencedtisdag den 15 februari 2011
  3. 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. 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. 5. 2011 - Why Develop for Android?tisdag den 15 februari 2011
  6. 6. 2011 - Why Develop for Android? I. Market share. The future is Android!tisdag den 15 februari 2011
  7. 7. 2011 - Why Develop for Android? I. Market share. The future is Android!tisdag den 15 februari 2011
  8. 8. 2011 - Why Develop for Android? II. Android will be everywhere!tisdag den 15 februari 2011
  9. 9. 2011 - Why Develop for Android? III. It’s open source, it’s free and it’s powerfultisdag den 15 februari 2011
  10. 10. 2011 - Why Develop for Android? IV. It’s Java!tisdag den 15 februari 2011
  11. 11. Android Platformtisdag den 15 februari 2011
  12. 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. 13. Android Platform Linux Process Default behavior App A Process ASystem starts App Atisdag den 15 februari 2011
  14. 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. 15. Android Platform Linux Process Configured behavior App A Process ASystem starts App Atisdag den 15 februari 2011
  16. 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. 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. 18. Android Platform Linux Process Configured behavior App A Process ASystem starts App Atisdag den 15 februari 2011
  19. 19. Android Platform Linux Process Configured behavior App A App A Process ASystem starts App starts App A componentstisdag den 15 februari 2011
  20. 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. 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. 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. 23. Android Platform Building .java .class .dex .jar .apktisdag den 15 februari 2011
  24. 24. Android and Java Runtime .dex App Resources Manifest apktisdag den 15 februari 2011
  25. 25. Android and Java Runtime .dex App Resources Manifest apk Optimized Dalvik VM Environmenttisdag den 15 februari 2011
  26. 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. 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. 28. Android Application Application Activity AndroidManifest.xml “Manifest” Activity Broadcast Content Service Receiver Provider Resourcestisdag den 15 februari 2011
  29. 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. 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. 31. Android Application Minimum Application Activity AndroidManifest.xml Plain UI application Resourcestisdag den 15 februari 2011
  32. 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. 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. 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. 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. 36. Android Application Resources Resource definitions /res /anim /fade_in.xml AndroidManifest.xml /drawable Activity /layout /values /xml /rawtisdag den 15 februari 2011
  37. 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. 38. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /layout_myactivity.xml /values /xml /rawtisdag den 15 februari 2011
  39. 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. 40. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /values /preferences.xml /xml /*.xml /rawtisdag den 15 februari 2011
  41. 41. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /values /xml /raw Arbitrary filestisdag den 15 februari 2011
  42. 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. 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. 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. 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. 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. 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. 48. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayouttisdag den 15 februari 2011
  49. 49. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayouttisdag den 15 februari 2011
  50. 50. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayouttisdag den 15 februari 2011
  51. 51. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayouttisdag den 15 februari 2011
  52. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 71. UI Lists Adapter <interface> Adapter BaseAdapter Cursor ArrayAdapter SimpleAdapter Adapter SimpleCursor Adaptertisdag den 15 februari 2011
  72. 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. 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. 74. User Experience Activity Lifecycle States Active Foreground Partly Paused obscured Completely Stopped obscuredtisdag den 15 februari 2011
  75. 75. User Experience Activity Lifecycle States Active Foreground Partly Paused obscured Active Completely Stopped obscured Activity stacktisdag den 15 februari 2011
  76. 76. User Experience Activity Lifecycle States Active Foreground Paused Partly Active obscured Stopped Completely Stopped obscured Activity stacktisdag den 15 februari 2011
  77. 77. User Experience Activity Lifecycle States Active Foreground Active Paused Partly Paused obscured Stopped Completely Stopped obscured Activity stacktisdag den 15 februari 2011
  78. 78. User Experience Activity Lifecycle Start Active Paused Stopped Finishtisdag den 15 februari 2011
  79. 79. User Experience Activity Lifecycle Start • System callbacks Active • Override in subclass Paused Stopped Finishtisdag den 15 februari 2011
  80. 80. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass Paused Stopped Finishtisdag den 15 februari 2011
  81. 81. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused Stopped Finishtisdag den 15 februari 2011
  82. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 95. User Experience Activity Tasktisdag den 15 februari 2011
  96. 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. 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. 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. 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. 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. 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. 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. 103. User Experience System Cleanup Background Process Problem Foreground MyActivity Some texttisdag den 15 februari 2011
  104. 104. User Experience System Cleanup Background Process Problem Foreground Background MyActivity MyActivity Other Some text Activity OtherActivity startstisdag den 15 februari 2011
  105. 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. 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. 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. 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. 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. 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. 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. 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. 113. User Experience Master the thread model Application Not Respondingtisdag den 15 februari 2011
  114. 114. User Experience Master the thread model Thread Model Process Atisdag den 15 februari 2011
  115. 115. User Experience Master the thread model Thread Model App A Process ASystem starts App Atisdag den 15 februari 2011
  116. 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. 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. 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. 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. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×