Android platform              Activity                         Cao Minh Vu                                             1  ...
Outline   What is activity   Starting activity   Shutting down activity   Activity lifecycle   Save state   Back sta...
What is activity   An application component       A screen with which user can interact       A window to draw its UI  ...
Creating an activity   Declare in manifest.xml   Implement xml layout (optional)   Extends from Activity               ...
Starting an activity   By name      Intent intent = new Intent(this, SignInActivity.class);      startActivity(intent); ...
Starting an activity (cont)   Start for result      Intent intent = new Intent((Intent.ACTION_PICK);      intent.setType(...
Shutting down an activity   Explicitly       Finish();   Implicitly       Let the system do it (when user press BACK H...
Activity lifecycle   onCreate(Bundle savedInstanceState)       initialize the essential components       setContentView...
Activity lifecycle (cont)   OnStop()       completely obscured by another activity        (=>background)       is not a...
Activity lifecycle (cont)                            10
Save state             11
Back stack   Android Manifest       "standard" (the default mode)       "singleTop"       "singleTask"       "singleI...
Configuration change   Screen orientation, change language...       Call onDestroy and onCreate()       Avoid ?        ...
Homework   Given activities started in order: A->B-C->D    Draw the back stack to illustrate 2 cases:       1. Start new...
Tips       15
Reference   http://developer.android.com/guide/topics/funda    mentals/activities.html                                   ...
Upcoming SlideShare
Loading in...5
×

Android platform activity

660

Published on

the Slide for second class with our Android Course. Revise the lesson then do the homework everyone who joined this class =)

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
660
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android platform activity

  1. 1. Android platform Activity Cao Minh Vu 1 cmv.ict@gmail.com
  2. 2. Outline What is activity Starting activity Shutting down activity Activity lifecycle Save state Back stack Tips 2
  3. 3. What is activity An application component  A screen with which user can interact  A window to draw its UI 3
  4. 4. Creating an activity Declare in manifest.xml Implement xml layout (optional) Extends from Activity 4
  5. 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. 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. 7. Shutting down an activity Explicitly  Finish(); Implicitly  Let the system do it (when user press BACK HW) Force Close 7
  8. 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 doesnt cover the entire 8 screen
  9. 9. Activity lifecycle (cont) OnStop()  completely obscured by another activity (=>background)  is not attached to the window manager 9
  10. 10. Activity lifecycle (cont) 10
  11. 11. Save state 11
  12. 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. 13. Configuration change Screen orientation, change language...  Call onDestroy and onCreate()  Avoid ? <activity android:name=".CustomGalleryActivity" android:configChanges="keyboardHidden| orientation"/> 13
  14. 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. 15. Tips 15
  16. 16. Reference http://developer.android.com/guide/topics/funda mentals/activities.html 16
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×