SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Android platform




              Activity




                         Cao Minh Vu
                                             1
                         cmv.ict@gmail.com
Outline

   What is activity
   Starting activity
   Shutting down activity
   Activity lifecycle
   Save state
   Back stack
   Tips

                             2
What is activity

   An application component
       A screen with which user can interact
       A window to draw its UI




                                                3
Creating an activity

   Declare in manifest.xml
   Implement xml layout (optional)
   Extends from Activity




                                      4
Starting an activity


   By name
      Intent intent = new Intent(this, SignInActivity.class);
      startActivity(intent);
   By action
      Intent intent = new Intent(“com.multi.action_show”);
      startActivity(intent);



                                                                5
Starting an activity (cont)

   Start for result
      Intent intent = new Intent((Intent.ACTION_PICK);
      intent.setType(“video/*”);
      startActivityForResult(intent, requestCode);


      protected void onActivityResult(int requestCode, int
      resultCode, Intent data) {
      }


                                                             6
Shutting down an activity

   Explicitly
       Finish();
   Implicitly
       Let the system do it (when user press BACK HW)
   Force Close




                                                         7
Activity lifecycle

   onCreate(Bundle savedInstanceState)
       initialize the essential components
       setContentView();
   onResume()
       just before the activity starts interacting with the
        user (foreground)
   OnPause()
       Another activity is in the foreground + focus, but this
        one is still visible => completely alive
       partially transparent or doesn't cover the entire      8
        screen
Activity lifecycle (cont)

   OnStop()
       completely obscured by another activity
        (=>background)
       is not attached to the window manager




                                                  9
Activity lifecycle (cont)




                            10
Save state




             11
Back stack

   Android Manifest
       "standard" (the default mode)
       "singleTop"
       "singleTask"
       "singleInstance"
   Flag
       FLAG_ACTIVITY_NEW_TASK (single task)
       FLAG_ACTIVITY_SINGLE_TOP (single top)
       FLAG_ACTIVITY_CLEAR_TOP
                                                12
Configuration change

   Screen orientation, change language...
       Call onDestroy and onCreate()
       Avoid ?
        <activity android:name=".CustomGalleryActivity"
           android:configChanges="keyboardHidden|
        orientation"/>




                                                          13
Homework
   Given activities started in order: A->B-C->D
    Draw the back stack to illustrate 2 cases:
       1. Start new activity D
       2. Start new activity B
    with modes: standard, singleTop, singleTask,
    singleInstance and Flag:
    FLAG_ACTIVITY_NEW_TASK,
    FLAG_ACTIVITY_SINGLE_TOP,
    FLAG_ACTIVITY_CLEAR_TOP
        Requirement:
       Draw back stack state when start new activity and
                                                            14
        then press back HW until the program is closed
Tips




       15
Reference

   http://developer.android.com/guide/topics/funda
    mentals/activities.html




                                                  16

Weitere ähnliche Inhalte

Andere mochten auch

よこへな3 15発表資料 最近ViewController をどんな感じで書いているか
よこへな3 15発表資料 最近ViewController をどんな感じで書いているかよこへな3 15発表資料 最近ViewController をどんな感じで書いているか
よこへな3 15発表資料 最近ViewController をどんな感じで書いているかYuichiro Suzuki
 
The agile pmp teaching an old dog new tricks
The agile pmp teaching an old dog new tricksThe agile pmp teaching an old dog new tricks
The agile pmp teaching an old dog new tricksLong Thay
 
Satire presentation
Satire presentationSatire presentation
Satire presentationmsmith94
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgetsHoang Vy Nguyen
 
Android platform overview
Android platform overviewAndroid platform overview
Android platform overviewHoang Vy Nguyen
 
Web Mashup Slides For Lesson 1
Web Mashup Slides For Lesson 1Web Mashup Slides For Lesson 1
Web Mashup Slides For Lesson 1Alvin Chua
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgetsHoang Vy Nguyen
 
Web Mashup Slides For Lesson 2
Web Mashup Slides For Lesson 2Web Mashup Slides For Lesson 2
Web Mashup Slides For Lesson 2Alvin Chua
 
Cheatsheet
CheatsheetCheatsheet
Cheatsheetbvaz
 
Android platform broadcast_receiver_intent
Android platform broadcast_receiver_intentAndroid platform broadcast_receiver_intent
Android platform broadcast_receiver_intentHoang Vy Nguyen
 
Shining Bright Blue In A Sea Of Green
Shining Bright Blue In A Sea Of GreenShining Bright Blue In A Sea Of Green
Shining Bright Blue In A Sea Of GreenDerek Oliver, PMP
 
Adapter and cache technique
Adapter and cache techniqueAdapter and cache technique
Adapter and cache techniqueHoang Vy Nguyen
 
Change Management
Change ManagementChange Management
Change ManagementGENPACT
 
Cheatsheet
CheatsheetCheatsheet
Cheatsheetbvaz
 

Andere mochten auch (16)

よこへな3 15発表資料 最近ViewController をどんな感じで書いているか
よこへな3 15発表資料 最近ViewController をどんな感じで書いているかよこへな3 15発表資料 最近ViewController をどんな感じで書いているか
よこへな3 15発表資料 最近ViewController をどんな感じで書いているか
 
The agile pmp teaching an old dog new tricks
The agile pmp teaching an old dog new tricksThe agile pmp teaching an old dog new tricks
The agile pmp teaching an old dog new tricks
 
Arisnb corel-draw
Arisnb corel-drawArisnb corel-draw
Arisnb corel-draw
 
Satire presentation
Satire presentationSatire presentation
Satire presentation
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgets
 
Android platform overview
Android platform overviewAndroid platform overview
Android platform overview
 
Bulimia
BulimiaBulimia
Bulimia
 
Web Mashup Slides For Lesson 1
Web Mashup Slides For Lesson 1Web Mashup Slides For Lesson 1
Web Mashup Slides For Lesson 1
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgets
 
Web Mashup Slides For Lesson 2
Web Mashup Slides For Lesson 2Web Mashup Slides For Lesson 2
Web Mashup Slides For Lesson 2
 
Cheatsheet
CheatsheetCheatsheet
Cheatsheet
 
Android platform broadcast_receiver_intent
Android platform broadcast_receiver_intentAndroid platform broadcast_receiver_intent
Android platform broadcast_receiver_intent
 
Shining Bright Blue In A Sea Of Green
Shining Bright Blue In A Sea Of GreenShining Bright Blue In A Sea Of Green
Shining Bright Blue In A Sea Of Green
 
Adapter and cache technique
Adapter and cache techniqueAdapter and cache technique
Adapter and cache technique
 
Change Management
Change ManagementChange Management
Change Management
 
Cheatsheet
CheatsheetCheatsheet
Cheatsheet
 

Ähnlich wie Android platform activity

Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & IntentsLope Emano
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)TECOS
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)Oum Saokosal
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android DevelopmentJussi Pohjolainen
 
Android N multi window
Android N multi windowAndroid N multi window
Android N multi windowYu-Wei Chuang
 
Skinning Android for Embedded Applications
Skinning Android for Embedded ApplicationsSkinning Android for Embedded Applications
Skinning Android for Embedded ApplicationsVIA Embedded
 
Pertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptxPertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptxMUHAMMADRIFKIPERMANA2
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycleSokngim Sa
 
android activity
android activityandroid activity
android activityDeepa Rani
 

Ähnlich wie Android platform activity (20)

Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
 
Mobile application development: part 1: Andriod Vs IOS
Mobile application development: part 1: Andriod Vs IOS Mobile application development: part 1: Andriod Vs IOS
Mobile application development: part 1: Andriod Vs IOS
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Introduction toandroid
Introduction toandroidIntroduction toandroid
Introduction toandroid
 
Activities.pptx
Activities.pptxActivities.pptx
Activities.pptx
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
 
Android N multi window
Android N multi windowAndroid N multi window
Android N multi window
 
Skinning Android for Embedded Applications
Skinning Android for Embedded ApplicationsSkinning Android for Embedded Applications
Skinning Android for Embedded Applications
 
Pertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptxPertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptx
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycle
 
android activity
android activityandroid activity
android activity
 

Kürzlich hochgeladen

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Kürzlich hochgeladen (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Android platform activity

  • 1. Android platform Activity Cao Minh Vu 1 cmv.ict@gmail.com
  • 2. Outline  What is activity  Starting activity  Shutting down activity  Activity lifecycle  Save state  Back stack  Tips 2
  • 3. What is activity  An application component  A screen with which user can interact  A window to draw its UI 3
  • 4. Creating an activity  Declare in manifest.xml  Implement xml layout (optional)  Extends from Activity 4
  • 5. Starting an activity  By name Intent intent = new Intent(this, SignInActivity.class); startActivity(intent);  By action Intent intent = new Intent(“com.multi.action_show”); startActivity(intent); 5
  • 6. Starting an activity (cont)  Start for result Intent intent = new Intent((Intent.ACTION_PICK); intent.setType(“video/*”); startActivityForResult(intent, requestCode); protected void onActivityResult(int requestCode, int resultCode, Intent data) { } 6
  • 7. Shutting down an activity  Explicitly  Finish();  Implicitly  Let the system do it (when user press BACK HW)  Force Close 7
  • 8. Activity lifecycle  onCreate(Bundle savedInstanceState)  initialize the essential components  setContentView();  onResume()  just before the activity starts interacting with the user (foreground)  OnPause()  Another activity is in the foreground + focus, but this one is still visible => completely alive  partially transparent or doesn't cover the entire 8 screen
  • 9. Activity lifecycle (cont)  OnStop()  completely obscured by another activity (=>background)  is not attached to the window manager 9
  • 12. Back stack  Android Manifest  "standard" (the default mode)  "singleTop"  "singleTask"  "singleInstance"  Flag  FLAG_ACTIVITY_NEW_TASK (single task)  FLAG_ACTIVITY_SINGLE_TOP (single top)  FLAG_ACTIVITY_CLEAR_TOP 12
  • 13. Configuration change  Screen orientation, change language...  Call onDestroy and onCreate()  Avoid ? <activity android:name=".CustomGalleryActivity" android:configChanges="keyboardHidden| orientation"/> 13
  • 14. Homework  Given activities started in order: A->B-C->D Draw the back stack to illustrate 2 cases:  1. Start new activity D  2. Start new activity B with modes: standard, singleTop, singleTask, singleInstance and Flag: FLAG_ACTIVITY_NEW_TASK, FLAG_ACTIVITY_SINGLE_TOP, FLAG_ACTIVITY_CLEAR_TOP Requirement:  Draw back stack state when start new activity and 14 then press back HW until the program is closed
  • 15. Tips 15
  • 16. Reference  http://developer.android.com/guide/topics/funda mentals/activities.html 16