SlideShare ist ein Scribd-Unternehmen logo
1 von 269
Downloaden Sie, um offline zu lesen
Android Application
                         Development
                                JFokus 2011


                              Anders Göransson




tisdag den 15 februari 2011
About You



                     •        Android experience

                              •   None / Little

                              •   Moderate / Experienced




tisdag den 15 februari 2011
Agenda
                                                     Android
                              Android               Application           UI
                               intro
                                                                                       User
                                                                                    Experience
                                        Broadcast
                    Service                               Content
                                        Receiver
                                                          Provider        Intents


 Application
  Design

                                                                     Android
                    Android                    External              Market
                 Fragmentation                  Tools
tisdag den 15 februari 2011
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
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 februari 2011
2011 - Why Develop for Android?

                               I. Market share. The future is Android!




tisdag den 15 februari 2011
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 powerful




tisdag den 15 februari 2011
2011 - Why Develop for Android?

                                         IV. It’s Java!




tisdag den 15 februari 2011
Android Platform




tisdag den 15 februari 2011
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 IPC




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Default behavior
                              App A

            Process A




System starts
    App A




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Default behavior
                              App A

            Process A




System starts                         System starts
    App A                                 App B
                                                      App B

                                         Process B




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Configured behavior
                              App A

            Process A




System starts
    App A




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Configured behavior
                              App A                   App A
                                                        App B
            Process A




System starts                         System starts
    App A                                 App B




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Configured behavior                                          - Same Process name
                                                                - Same User Id
                                                                - Same signing cert
                              App A                   App A
                                                        App B
            Process A




System starts                         System starts
    App A                                 App B




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Configured behavior
                              App A

            Process A




System starts
    App A




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Configured behavior
                              App A                 App A

            Process A




System starts                          App starts
    App A                             components




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Configured behavior
                              App A                 App A           App A

            Process A




System starts                          App starts    App starts
    App A                             components     component


                                                        Process B




tisdag den 15 februari 2011
Android Platform

                                  Linux Process
    Configured behavior
                              App A                 App A           App A

            Process A




                                                                       IPC
System starts                          App starts    App starts
    App A                             components     component


                                                        Process B




tisdag den 15 februari 2011
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
Android Platform

                                      Building


                              .java      .class   .dex



                                         .jar     .apk




tisdag den 15 februari 2011
Android and Java

                                     Runtime
                                      .dex
                              App   Resources
                                     Manifest
                              apk




tisdag den 15 februari 2011
Android and Java

                                     Runtime
                                      .dex
                              App   Resources
                                     Manifest
                              apk
                                     Optimized
                       Dalvik VM    Environment




tisdag den 15 februari 2011
Android and Java

                                     Runtime
                                      .dex
                              App   Resources
                                     Manifest
                              apk
                                     Optimized
                       Dalvik VM    Environment

                                    Linux properties
                   Linux process
                                       - Process Id
                                       - User Id
                                       - Thread model




tisdag den 15 februari 2011
Agenda
                                                     Android
                              Android               Application           UI
                               intro
                                                                                       User
                                                                                    Experience
                                        Broadcast
                    Service                               Content
                                        Receiver
                                                          Provider        Intents


 Application
  Design

                                                                     Android
                    Android                    External              Market
                 Fragmentation                  Tools
tisdag den 15 februari 2011
Android Application
                                                    Application

                                        Activity
                                                                    AndroidManifest.xml
                “Manifest”
                   Activity




                                        Broadcast        Content
                              Service
                                        Receiver         Provider
                                                                          Resources




tisdag den 15 februari 2011
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




tisdag den 15 februari 2011
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


                                   = Component


tisdag den 15 februari 2011
Android Application

                                              Minimum
                                      Application


                              Activity       AndroidManifest.xml




                                                                   Plain UI application
                              Resources




tisdag den 15 februari 2011
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
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()

       Finish

tisdag den 15 februari 2011
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 change

tisdag den 15 februari 2011
Android Application

                               Resources

              • Multimedia files
              • Images
       AndroidManifest.xml

              • XML -files
            Activity

                 • Layouts
                 • Animations
                 • Values (strings, dimensions, colors)
                 • Menu-definitions
                 • Preferences
tisdag den 15 februari 2011
Android Application                     Resources

                                  Resource definitions
             /res


                              /anim             /fade_in.xml

       AndroidManifest.xml
                          /drawable
                   Activity


                              /layout


                              /values


                               /xml


                               /raw
tisdag den 15 februari 2011
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


                               /raw
tisdag den 15 februari 2011
Android Application                     Resources

                                  Resource definitions
             /res


                              /anim

       AndroidManifest.xml
                          /drawable
                   Activity


                              /layout               /layout_myactivity.xml


                              /values


                               /xml


                               /raw
tisdag den 15 februari 2011
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


                               /raw
tisdag den 15 februari 2011
Android Application                     Resources

                                  Resource definitions
             /res


                              /anim

       AndroidManifest.xml
                          /drawable
                   Activity


                              /layout


                              /values

                                               /preferences.xml
                               /xml
                                                     /*.xml

                               /raw
tisdag den 15 februari 2011
Android Application                     Resources

                                  Resource definitions
             /res


                              /anim

       AndroidManifest.xml
                          /drawable
                   Activity


                              /layout


                              /values


                               /xml


                               /raw            Arbitrary files
tisdag den 15 februari 2011
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;
                                                          }
                                                      }




                               /raw
tisdag den 15 februari 2011
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;
                                                          }
                                                      }




                               /raw
tisdag den 15 februari 2011
Agenda
                                                     Android
                              Android               Application           UI
                               intro
                                                                                       User
                                                                                    Experience
                                        Broadcast
                    Service                               Content
                                        Receiver
                                                          Provider        Intents


 Application
  Design

                                                                     Android
                    Android                    External              Market
                 Fragmentation                  Tools
tisdag den 15 februari 2011
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            object

tisdag den 15 februari 2011
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           object

tisdag den 15 februari 2011
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           View


tisdag den 15 februari 2011
UI

                                               Layouts

                     •        Implements ViewGroup

                     •        Common layouts
       AndroidManifest.xml
                        •
                   Activity
                                LinearLayout

                        •       RelativeLayout

                        •       TableLayout




tisdag den 15 februari 2011
UI

                                               Layouts

                     •        Implements ViewGroup

                     •        Common layouts
       AndroidManifest.xml
                        •
                   Activity
                                LinearLayout

                        •       RelativeLayout

                        •       TableLayout




tisdag den 15 februari 2011
UI

                                               Layouts

                     •        Implements ViewGroup

                     •        Common layouts
       AndroidManifest.xml
                        •
                   Activity
                                LinearLayout

                        •       RelativeLayout

                        •       TableLayout




tisdag den 15 februari 2011
UI

                                               Layouts

                     •        Implements ViewGroup

                     •        Common layouts
       AndroidManifest.xml
                        •
                   Activity
                                LinearLayout

                        •       RelativeLayout

                        •       TableLayout




tisdag den 15 februari 2011
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
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   View

tisdag den 15 februari 2011
UI

                                                   Drawing UI
                   •          Top-down traversal

                       •        Measure

                      • fill_parent, wrap_content, “fix value”
       AndroidManifest.xml
               •
            ActivityLayout

                   • layout_*
                                   Linear
                                   Layout




                                            Text    Text
     EditText                 Button
                                            View    View

tisdag den 15 februari 2011
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
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
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
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
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
UI

                                  Accessing Resources
public 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 Id


tisdag den 15 februari 2011
UI

                                  Accessing Resources
public 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
UI

                                                   Lists


                     •        Commonly used

                     •        Needs to be efficient

                              •   Not consume too much memory

                              •   Fast scrolling

                     •        Android-way of handling lists efficiently




tisdag den 15 februari 2011
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 caching
tisdag den 15 februari 2011
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 caching
tisdag den 15 februari 2011
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 caching
tisdag den 15 februari 2011
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 caching
tisdag den 15 februari 2011
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 caching
tisdag den 15 februari 2011
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 caching
tisdag den 15 februari 2011
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 caching
tisdag den 15 februari 2011
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 caching
tisdag den 15 februari 2011
UI                     Lists

                                     Adapter
                                      <interface>
                                        Adapter



                                      BaseAdapter



                                       Cursor       ArrayAdapter
                     SimpleAdapter
                                       Adapter


                                     SimpleCursor
                                        Adapter

tisdag den 15 februari 2011
Agenda
                                                     Android
                              Android               Application           UI
                               intro
                                                                                       User
                                                                                    Experience
                                        Broadcast
                    Service                               Content
                                        Receiver
                                                          Provider        Intents


 Application
  Design

                                                                     Android
                    Android                    External              Market
                 Fragmentation                  Tools
tisdag den 15 februari 2011
User Experience

                 •       Critical for application success

                 •       UX

                     •        UI design

                              •   Employ a good designer

                     •        Deliver expected behavior

                              •   Master the Activity lifecycle

                     •        Responsive

                              •   Master the thread handling


tisdag den 15 februari 2011
User Experience                Activity

                                          Lifecycle
               States

                 Active       Foreground



                                Partly
                Paused
                               obscured


                              Completely
               Stopped
                               obscured


tisdag den 15 februari 2011
User Experience                Activity

                                          Lifecycle
               States

                 Active       Foreground



                                Partly
                Paused
                               obscured
                                                                 Active

                              Completely
               Stopped
                               obscured
                                                Activity stack


tisdag den 15 februari 2011
User Experience                Activity

                                          Lifecycle
               States

                 Active       Foreground



                Paused
                                Partly                           Active
                               obscured
                                                                 Stopped

                              Completely
               Stopped
                               obscured
                                                Activity stack


tisdag den 15 februari 2011
User Experience                Activity

                                          Lifecycle
               States

                 Active       Foreground

                                                                 Active

                Paused
                                Partly                           Paused
                               obscured
                                                                 Stopped

                              Completely
               Stopped
                               obscured
                                                Activity stack


tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start




              Active


             Paused


           Stopped


             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start




                                            •   System callbacks

              Active                        •   Override in subclass


             Paused


           Stopped


             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start

            onCreate()

             onStart()

          onResume()                        •   System callbacks

              Active                        •   Override in subclass


             Paused


           Stopped


             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start

            onCreate()

             onStart()

          onResume()                        •   System callbacks

              Active                        •   Override in subclass

            onPause()

             Paused


           Stopped


             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start

            onCreate()

             onStart()

          onResume()                        •   System callbacks

              Active                        •   Override in subclass

            onPause()

             Paused
             onStop()

           Stopped


             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start

            onCreate()

             onStart()

          onResume()                        •   System callbacks

              Active                        •   Override in subclass

            onPause()

             Paused
             onStop()

           Stopped
          onDestroy()

             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start

            onCreate()

             onStart()

          onResume()                        •   System callbacks

              Active                        •   Override in subclass

            onPause()

             Paused
             onStop()

           Stopped
          onDestroy()

             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start

            onCreate()

             onStart()           onRestart()

          onResume()                           •   System callbacks

              Active                           •   Override in subclass

            onPause()

             Paused
             onStop()

           Stopped
          onDestroy()

             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start

            onCreate()

             onStart()           onRestart()
                                               Entire lifetime
          onResume()
                                               - Long lived objects
                                               - Create UI
              Active
            onPause()

             Paused
             onStop()

           Stopped
          onDestroy()

             Finish
tisdag den 15 februari 2011
User Experience               Activity

                                         Lifecycle
               Start

            onCreate()

             onStart()           onRestart()
                                               Visible lifetime
          onResume()
                                               - Visible but possibly not in
                                               foreground
              Active
            onPause()

             Paused
             onStop()

           Stopped
          onDestroy()

             Finish
tisdag den 15 februari 2011
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()

             Finish
tisdag den 15 februari 2011
User Experience                Activity

                              Activity transition
                                                    Tip
      Activity 1                           Save state in onPause()

              Active

            onPause()




                                                    I         Active

             onStop()
                                            Activity stack
           Stopped
tisdag den 15 februari 2011
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
           Stopped
tisdag den 15 februari 2011
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
           Stopped
tisdag den 15 februari 2011
User Experience               Activity

                              Lifecycle Extras
               Start

            onCreate()

             onStart()           onRestart()
                                               onPostCreate()
          onResume()
                                               onPostResume()
              Active
            onPause()

             Paused
             onStop()

           Stopped
          onDestroy()

             Finish
tisdag den 15 februari 2011
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()

             Finish
tisdag den 15 februari 2011
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
User Experience               Activity

                                         Task




tisdag den 15 februari 2011
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 process



tisdag den 15 februari 2011
User Experience                            System Cleanup

                                      Process Hierarchy
                              - Activity in the foreground (onResume called)
                              - Service executing platform callback (onCreate, onStartCommand, onDestroy)
       Foreground
                              - BroadcastReceiver executing platform callback




tisdag den 15 februari 2011
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




tisdag den 15 februari 2011
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




tisdag den 15 februari 2011
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




tisdag den 15 februari 2011
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
          Empty




tisdag den 15 februari 2011
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
User Experience                    System Cleanup

                                 Background Process
                                      Problem
                    Foreground




              MyActivity
                Some text




tisdag den 15 februari 2011
User Experience                           System Cleanup

                                   Background Process
                                        Problem
                    Foreground                   Background




              MyActivity                    MyActivity
                                              Other
                Some text                     Activity




                                 OtherActivity
                                 starts




tisdag den 15 februari 2011
User Experience                           System Cleanup

                                   Background Process
                                        Problem
                    Foreground                   Background
                                                                           Killed
              MyActivity                    MyActivity
                                              Other                        Other
                                              Activity                     Activity
                Some text




                                 OtherActivity                System shuts down
                                 starts                       MyActivity




tisdag den 15 februari 2011
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
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*-methods




tisdag den 15 februari 2011
User Experience                           System Cleanup

                                   Background Process
                                        Solution
                    Foreground                   Background
                                                                           Killed
              MyActivity                    MyActivity
                                              Other                        Other
                                              Activity                     Activity
                Some text




                                 OtherActivity                System shuts down
                                 starts                       MyActivity




tisdag den 15 februari 2011
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
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
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
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 thread




tisdag den 15 februari 2011
User Experience               Master the thread model

                  Application Not Responding




tisdag den 15 februari 2011
User Experience               Master the thread model

                                     Thread Model



            Process A




tisdag den 15 februari 2011
User Experience               Master the thread model

                                     Thread Model


                              App A

            Process A




System starts
    App A



tisdag den 15 februari 2011
User Experience               Master the thread model

                                     Thread Model


                              App A                     App A

            Process A                                       UI thread




System starts                            App starts
    App A                               components



tisdag den 15 februari 2011
User Experience               Master the thread model

                                     Thread Model


                              App A                     App A                 App A

            Process A                                       UI thread                    UI thread

                                                                                   ...
                                                                        Worker threads




System starts                            App starts            App starts
    App A                               components           worker threads



tisdag den 15 februari 2011
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 threads




System starts                            App starts            App starts
    App A                               components           worker threads



tisdag den 15 februari 2011
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 threads




System starts                            App starts                 App starts
    App A                               components                worker threads
                                                  - Time consuming tasks
                                                  - No UI manipulations
                                                                                !
tisdag den 15 februari 2011
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
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
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 shouldn't 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
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

Weitere ähnliche Inhalte

Ähnlich wie Android Application Development at JFokus 2011

Android presentation 2011
Android presentation 2011Android presentation 2011
Android presentation 2011Bram Vandeputte
 
Roadshow Europe M&C Saatchi Mobile - Chris Cannacott
Roadshow Europe M&C Saatchi Mobile - Chris Cannacott Roadshow Europe M&C Saatchi Mobile - Chris Cannacott
Roadshow Europe M&C Saatchi Mobile - Chris Cannacott mobilesquared Ltd
 
Metro Style Apps - Whats there for Developers
Metro Style Apps - Whats there for DevelopersMetro Style Apps - Whats there for Developers
Metro Style Apps - Whats there for DevelopersJitendra Soni
 
Appcelerator Titanium App Development
Appcelerator Titanium App DevelopmentAppcelerator Titanium App Development
Appcelerator Titanium App DevelopmentAnubavam
 
Few steps into Android
Few steps into AndroidFew steps into Android
Few steps into AndroidAlexey Buzdin
 
OTA WIreless Deployment
OTA WIreless DeploymentOTA WIreless Deployment
OTA WIreless Deploymentalekseyn
 
Android development courses online
Android development courses onlineAndroid development courses online
Android development courses onlineTexilaedu
 
Android Workshop Presentation
Android Workshop PresentationAndroid Workshop Presentation
Android Workshop PresentationNAILBITER
 
Android Workshop Session 1
Android Workshop Session 1Android Workshop Session 1
Android Workshop Session 1NAILBITER
 
Automated Mobile Testing using Appium.pdf
Automated Mobile Testing using Appium.pdfAutomated Mobile Testing using Appium.pdf
Automated Mobile Testing using Appium.pdfAnand722237
 
Building an SSO platform in PHP (Zend Webinar Edition)
Building an SSO platform in PHP (Zend Webinar Edition)Building an SSO platform in PHP (Zend Webinar Edition)
Building an SSO platform in PHP (Zend Webinar Edition)Ivo Jansch
 
OpenMobile ACL bringing Android apps to TIZEN
OpenMobile ACL bringing Android apps to TIZENOpenMobile ACL bringing Android apps to TIZEN
OpenMobile ACL bringing Android apps to TIZENRyo Jin
 
IOSAPPDevelopment 2011CS010103.pptx
IOSAPPDevelopment 2011CS010103.pptxIOSAPPDevelopment 2011CS010103.pptx
IOSAPPDevelopment 2011CS010103.pptxJiminJimin16
 
2011 The Year of Web apps
2011 The Year of Web apps2011 The Year of Web apps
2011 The Year of Web appsJungHyuk Kwon
 
Basics of Android
Basics of Android Basics of Android
Basics of Android sabi_123
 
Automated Testing and Continuous Deployment for Mobile Apps with Jenkins
Automated Testing and Continuous Deployment for Mobile Apps with Jenkins Automated Testing and Continuous Deployment for Mobile Apps with Jenkins
Automated Testing and Continuous Deployment for Mobile Apps with Jenkins CloudBees
 
Olivier meetup-boston-2013-jan-21-v2
Olivier meetup-boston-2013-jan-21-v2Olivier meetup-boston-2013-jan-21-v2
Olivier meetup-boston-2013-jan-21-v2Olivier Eeckhoutte
 
Embracing mobile platforms | nascent at carmel ventures
Embracing mobile platforms | nascent at carmel venturesEmbracing mobile platforms | nascent at carmel ventures
Embracing mobile platforms | nascent at carmel venturesnascent
 
What is Google App Engine?
What is Google App Engine?What is Google App Engine?
What is Google App Engine?weschwee
 

Ähnlich wie Android Application Development at JFokus 2011 (20)

Android presentation 2011
Android presentation 2011Android presentation 2011
Android presentation 2011
 
Sdk overview
Sdk overviewSdk overview
Sdk overview
 
Roadshow Europe M&C Saatchi Mobile - Chris Cannacott
Roadshow Europe M&C Saatchi Mobile - Chris Cannacott Roadshow Europe M&C Saatchi Mobile - Chris Cannacott
Roadshow Europe M&C Saatchi Mobile - Chris Cannacott
 
Metro Style Apps - Whats there for Developers
Metro Style Apps - Whats there for DevelopersMetro Style Apps - Whats there for Developers
Metro Style Apps - Whats there for Developers
 
Appcelerator Titanium App Development
Appcelerator Titanium App DevelopmentAppcelerator Titanium App Development
Appcelerator Titanium App Development
 
Few steps into Android
Few steps into AndroidFew steps into Android
Few steps into Android
 
OTA WIreless Deployment
OTA WIreless DeploymentOTA WIreless Deployment
OTA WIreless Deployment
 
Android development courses online
Android development courses onlineAndroid development courses online
Android development courses online
 
Android Workshop Presentation
Android Workshop PresentationAndroid Workshop Presentation
Android Workshop Presentation
 
Android Workshop Session 1
Android Workshop Session 1Android Workshop Session 1
Android Workshop Session 1
 
Automated Mobile Testing using Appium.pdf
Automated Mobile Testing using Appium.pdfAutomated Mobile Testing using Appium.pdf
Automated Mobile Testing using Appium.pdf
 
Building an SSO platform in PHP (Zend Webinar Edition)
Building an SSO platform in PHP (Zend Webinar Edition)Building an SSO platform in PHP (Zend Webinar Edition)
Building an SSO platform in PHP (Zend Webinar Edition)
 
OpenMobile ACL bringing Android apps to TIZEN
OpenMobile ACL bringing Android apps to TIZENOpenMobile ACL bringing Android apps to TIZEN
OpenMobile ACL bringing Android apps to TIZEN
 
IOSAPPDevelopment 2011CS010103.pptx
IOSAPPDevelopment 2011CS010103.pptxIOSAPPDevelopment 2011CS010103.pptx
IOSAPPDevelopment 2011CS010103.pptx
 
2011 The Year of Web apps
2011 The Year of Web apps2011 The Year of Web apps
2011 The Year of Web apps
 
Basics of Android
Basics of Android Basics of Android
Basics of Android
 
Automated Testing and Continuous Deployment for Mobile Apps with Jenkins
Automated Testing and Continuous Deployment for Mobile Apps with Jenkins Automated Testing and Continuous Deployment for Mobile Apps with Jenkins
Automated Testing and Continuous Deployment for Mobile Apps with Jenkins
 
Olivier meetup-boston-2013-jan-21-v2
Olivier meetup-boston-2013-jan-21-v2Olivier meetup-boston-2013-jan-21-v2
Olivier meetup-boston-2013-jan-21-v2
 
Embracing mobile platforms | nascent at carmel ventures
Embracing mobile platforms | nascent at carmel venturesEmbracing mobile platforms | nascent at carmel ventures
Embracing mobile platforms | nascent at carmel ventures
 
What is Google App Engine?
What is Google App Engine?What is Google App Engine?
What is Google App Engine?
 

Kürzlich hochgeladen

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Kürzlich hochgeladen (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Android Application Development at JFokus 2011

  • 1. Android Application Development JFokus 2011 Anders Göransson tisdag den 15 februari 2011
  • 2. About You • Android experience • None / Little • Moderate / Experienced tisdag 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 Tools tisdag 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 powerful tisdag den 15 februari 2011
  • 10. 2011 - Why Develop for Android? IV. It’s Java! tisdag den 15 februari 2011
  • 11. Android Platform tisdag 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 IPC tisdag den 15 februari 2011
  • 13. Android Platform Linux Process Default behavior App A Process A System starts App A tisdag den 15 februari 2011
  • 14. Android Platform Linux Process Default behavior App A Process A System starts System starts App A App B App B Process B tisdag den 15 februari 2011
  • 15. Android Platform Linux Process Configured behavior App A Process A System starts App A tisdag den 15 februari 2011
  • 16. Android Platform Linux Process Configured behavior App A App A App B Process A System starts System starts App A App B tisdag 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 A System starts System starts App A App B tisdag den 15 februari 2011
  • 18. Android Platform Linux Process Configured behavior App A Process A System starts App A tisdag den 15 februari 2011
  • 19. Android Platform Linux Process Configured behavior App A App A Process A System starts App starts App A components tisdag den 15 februari 2011
  • 20. Android Platform Linux Process Configured behavior App A App A App A Process A System starts App starts App starts App A components component Process B tisdag den 15 februari 2011
  • 21. Android Platform Linux Process Configured behavior App A App A App A Process A IPC System starts App starts App starts App A components component Process B tisdag 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 .apk tisdag den 15 februari 2011
  • 24. Android and Java Runtime .dex App Resources Manifest apk tisdag den 15 februari 2011
  • 25. Android and Java Runtime .dex App Resources Manifest apk Optimized Dalvik VM Environment tisdag 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 model tisdag 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 Tools tisdag den 15 februari 2011
  • 28. Android Application Application Activity AndroidManifest.xml “Manifest” Activity Broadcast Content Service Receiver Provider Resources tisdag 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 Resources tisdag 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 = Component tisdag den 15 februari 2011
  • 31. Android Application Minimum Application Activity AndroidManifest.xml Plain UI application Resources tisdag 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() Finish tisdag 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 change tisdag den 15 februari 2011
  • 35. Android Application Resources • Multimedia files • Images AndroidManifest.xml • XML -files Activity • Layouts • Animations • Values (strings, dimensions, colors) • Menu-definitions • Preferences tisdag den 15 februari 2011
  • 36. Android Application Resources Resource definitions /res /anim /fade_in.xml AndroidManifest.xml /drawable Activity /layout /values /xml /raw tisdag 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 /raw tisdag den 15 februari 2011
  • 38. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /layout_myactivity.xml /values /xml /raw tisdag 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 /raw tisdag den 15 februari 2011
  • 40. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /values /preferences.xml /xml /*.xml /raw tisdag den 15 februari 2011
  • 41. Android Application Resources Resource definitions /res /anim AndroidManifest.xml /drawable Activity /layout /values /xml /raw Arbitrary files tisdag 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; } } /raw tisdag 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; } } /raw tisdag 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 Tools tisdag 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 object tisdag 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 object tisdag 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 View tisdag den 15 februari 2011
  • 48. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayout tisdag den 15 februari 2011
  • 49. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayout tisdag den 15 februari 2011
  • 50. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayout tisdag den 15 februari 2011
  • 51. UI Layouts • Implements ViewGroup • Common layouts AndroidManifest.xml • Activity LinearLayout • RelativeLayout • TableLayout tisdag 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 View tisdag 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 View tisdag 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 Resources public 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 Id tisdag den 15 februari 2011
  • 61. UI Accessing Resources public 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 efficiently tisdag 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 caching tisdag 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 caching tisdag 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 caching tisdag 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 caching tisdag 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 caching tisdag 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 caching tisdag 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 caching tisdag 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 caching tisdag den 15 februari 2011
  • 71. UI Lists Adapter <interface> Adapter BaseAdapter Cursor ArrayAdapter SimpleAdapter Adapter SimpleCursor Adapter tisdag 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 Tools tisdag 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 handling tisdag den 15 februari 2011
  • 74. User Experience Activity Lifecycle States Active Foreground Partly Paused obscured Completely Stopped obscured tisdag den 15 februari 2011
  • 75. User Experience Activity Lifecycle States Active Foreground Partly Paused obscured Active Completely Stopped obscured Activity stack tisdag den 15 februari 2011
  • 76. User Experience Activity Lifecycle States Active Foreground Paused Partly Active obscured Stopped Completely Stopped obscured Activity stack tisdag den 15 februari 2011
  • 77. User Experience Activity Lifecycle States Active Foreground Active Paused Partly Paused obscured Stopped Completely Stopped obscured Activity stack tisdag den 15 februari 2011
  • 78. User Experience Activity Lifecycle Start Active Paused Stopped Finish tisdag den 15 februari 2011
  • 79. User Experience Activity Lifecycle Start • System callbacks Active • Override in subclass Paused Stopped Finish tisdag den 15 februari 2011
  • 80. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass Paused Stopped Finish tisdag den 15 februari 2011
  • 81. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused Stopped Finish tisdag den 15 februari 2011
  • 82. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused onStop() Stopped Finish tisdag den 15 februari 2011
  • 83. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused onStop() Stopped onDestroy() Finish tisdag den 15 februari 2011
  • 84. User Experience Activity Lifecycle Start onCreate() onStart() onResume() • System callbacks Active • Override in subclass onPause() Paused onStop() Stopped onDestroy() Finish tisdag 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() Finish tisdag 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() Finish tisdag 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() Finish tisdag 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() Finish tisdag den 15 februari 2011
  • 89. User Experience Activity Activity transition Tip Activity 1 Save state in onPause() Active onPause() I Active onStop() Activity stack Stopped tisdag 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 Stopped tisdag 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 Stopped tisdag den 15 februari 2011
  • 92. User Experience Activity Lifecycle Extras Start onCreate() onStart() onRestart() onPostCreate() onResume() onPostResume() Active onPause() Paused onStop() Stopped onDestroy() Finish tisdag 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() Finish tisdag 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 Task tisdag 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 process tisdag 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 callback tisdag 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 Visible tisdag 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) Service tisdag 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) Background tisdag 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 Empty tisdag 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 text tisdag den 15 februari 2011
  • 104. User Experience System Cleanup Background Process Problem Foreground Background MyActivity MyActivity Other Some text Activity OtherActivity starts tisdag 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 MyActivity tisdag 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*-methods tisdag 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 MyActivity tisdag 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 thread tisdag den 15 februari 2011
  • 113. User Experience Master the thread model Application Not Responding tisdag den 15 februari 2011
  • 114. User Experience Master the thread model Thread Model Process A tisdag den 15 februari 2011
  • 115. User Experience Master the thread model Thread Model App A Process A System starts App A tisdag den 15 februari 2011
  • 116. User Experience Master the thread model Thread Model App A App A Process A UI thread System starts App starts App A components tisdag 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 threads System starts App starts App starts App A components worker threads tisdag 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 threads System starts App starts App starts App A components worker threads tisdag 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 threads System 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 shouldn't 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