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@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
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...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
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
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
+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...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 

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