SlideShare a Scribd company logo
1 of 16
Download to read 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

More Related Content

Viewers also liked

よこへな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
 

Viewers also liked (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
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
panagenda
 
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
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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)
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
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...
 
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
 
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
 
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
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
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
 

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