SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
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

Mais conteúdo relacionado

Destaque

よこへな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 tricks
Long Thay
 
Satire presentation
Satire presentationSatire presentation
Satire presentation
msmith94
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgets
Hoang Vy Nguyen
 
Android platform overview
Android platform overviewAndroid platform overview
Android platform overview
Hoang Vy Nguyen
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgets
Hoang Vy Nguyen
 
Android platform broadcast_receiver_intent
Android platform broadcast_receiver_intentAndroid platform broadcast_receiver_intent
Android platform broadcast_receiver_intent
Hoang Vy Nguyen
 
Cheatsheet
CheatsheetCheatsheet
Cheatsheet
bvaz
 

Destaque (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
 

Semelhante a Android platform activity

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
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
Utkarsh Mankad
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
DHIRAJ PRAVIN
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 
android activity
android activityandroid activity
android activity
Deepa Rani
 

Semelhante a 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
 

Último

+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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?
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+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...
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

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