Your SlideShare is downloading. ×
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Android Activities, Applications, Lifecycles, & Lifetimes
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Android Activities, Applications, Lifecycles, & Lifetimes

744

Published on

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

No Downloads
Views
Total Views
744
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Android Activities, Applications, Lifecycles, & Lifetimes Vladimir Kulyukinwww.youtube.com/vkedco www.vkedco.blogspot.com
  • 2. Outline ● Activity vs. Application ● Activities – Lifecycle – Lifetimes – Essential States – Callback Methods ● Applications – Security Sandboxes – Process Sharing – Principle of Least Privilegewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 3. Basic Definitionswww.youtube.com/vkedco www.vkedco.blogspot.com
  • 4. Activity ● Activity is an application component ● Activity provides the user a screen with which the user can interact ● Each activity is assigned a window in which it can draw its interface ● One activity can start another activity ● When an new activity starts it is pushed on the back stack and receives user focus ● The back stack is a last-in-first-out data structurewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 5. Application ● Applications are packaged executables (.apk files) ● All application code, data, and resources reside in a single archive .apk file ● Applications consist of one or more components, such as activites, services, content providers, and broadcast receivers ● The manifest file must declare all components in the application and declare all application requirementswww.youtube.com/vkedco www.vkedco.blogspot.com
  • 6. Process & Program ● A process is an executing/running instance of a program ● Processes are also referred to as tasks ● A program is an executable file stored in external memory, e.g. hard disk drives ● An executable file is a binary file that has been compiled from source code (Java) into machine code (Dalvik JVM byte code) ● A program is a passive entity until starts to run, i.e., becomes a processwww.youtube.com/vkedco www.vkedco.blogspot.com
  • 7. Activitieswww.youtube.com/vkedco www.vkedco.blogspot.com
  • 8. Activitys Lifecycle ● An actvitys lifecycle is a set of states ● When the current state of an activity changes, the Android OS notifies the activity of that change ● The Android developer manages the activitys lifecycle by implementing the standard callback methods that are called on the activity object when its state changes (e.g., activity is created, stopped, resumed, and destroyed) ● Callback implementation is the only leverage the developer has over activitieswww.youtube.com/vkedco www.vkedco.blogspot.com
  • 9. Activitys Lifecycle: Callback Methods public class MyActivity { // The activity is created public void onCreate(Bundle savedInstanceState) { } // The activity is about to become visible protected void onStart() { } //The activity is visible (it is resumed) protected void onResume() { } // Another activity is taking focus (it is paused) protected void onPause() { } // The activity is no longer visible (it is stopped) protected void onStop() { } // The activity is about to be destroyed protected void onDestroy() { } }www.youtube.com/vkedco www.vkedco.blogspot.com
  • 10. Image Source: http://developer.android.com/guide/components/activities.html#Lifecyclewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 11. Activitys Lifetimeswww.youtube.com/vkedco www.vkedco.blogspot.com
  • 12. Activitys Lifetimes ● Entire lifetime – from onCreate() to onDestroy() ● Visible lifetime – from onStart() to onStop(): user sees the activity and interacts with it ● Foreground lifetime – from onResume() to onPause(): activity is in front of all other activities on screen and has user focus; code in onResume() and onPause() should be lightweight because activities frequently transition in and out of foregroundwww.youtube.com/vkedco www.vkedco.blogspot.com
  • 13. What is Done in Each Lifetime ● Entire lifetime – sets up the activitys global state in onCreate() and releases that global state in onDestroy() ● Visible lifetime – maintains the resources needed to show the activity to the user, e.g. register and unregister BroadcastReceivers ● Foreground lifetime – maintain the resources needed to interact with the user directly, methods should be lightweightwww.youtube.com/vkedco www.vkedco.blogspot.com
  • 14. Activitys Three Essential States ● Running/Resumed – this activity is in the foreground of the screen and receives user focus ● Paused – This activity is partially obscured by another activity that gets in the foreground and user focus – Paused activity objects are 1) in memory, 2) attached to Window Manager, 3) killable in extremely low memory conditions ● Stopped – This activity is completely obscured by another activity – Stopped activity objects are 1) in memory, 2) detached from Window Manager, 3) killable when memory is needed somewhere elsewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 15. Callback Methodswww.youtube.com/vkedco www.vkedco.blogspot.com
  • 16. Activity.onCreate() ● onCreate() is called when the activity is created ● onCreate() is the place to create views and do data binding ● onCreate() takes a Bundle that contains the previous state of the activity if that state was persisted ● onCreate() is followed by onStart() ● The hosting process cannot be killed after this method returns without executing another line of the activitys code, i.e., the hosting process is not killablewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 17. Activity.onRestart() ● onRestart() is called after the activity is stopped and right before it is started again ● onRestart() is followed by onStart() ● The hosting process cannot be killed after this method returns without executing another line of the activitys code, i.e., the hosting process is not killablewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 18. Activity.onStart() ● onStart() is called when the activity is visible to the user ● onStart() is followed 1) by onResume() if the activity gets into foreground and 2) by onStop() if it becomes hidden ● The hosting process cannot be killed after this method returns without executing another line of the activitys code, i.e., the hosting process is not killablewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 19. Activity.onResume() ● onResume() is called right before the user begins to interact with the activity; the activity is taking user input ● onResume() is followed by onPause() ● The hosting process cannot be killed after this method returns without executing another line of the activitys code, i.e., the hosting process is not killablewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 20. Activity.onPause() ● onPause() is called right before Android OS resumes a different activity ● onPause() is used to persist data, stop CPU consumables (animations, downloads, etc.) ● onPause() is followed 1) by onResume() if the activity returns back to front or 2) by onStop() if it becomes hidden – Pre 3.0: The hosting process can be killed after this method returns without executing another line of the activitys code – Post 3.0: The hosting process cannot be killed after this method returns without executing another line of the activitys codewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 21. Activity.onStop() ● onStop() is called when the activity is no longer visible to the user because 1) Android OS begins to destroy the activity or 2) another activity is started or resumed and is covering this activity ● onStop() is followed 1) by onRestart() if the activity is coming back to the foreground or 2) by onDestroy() if the activity is destroyed ● The hosting process can be killed after this method returns without executing another line of the activitys code, i.e., the hosting process is killablewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 22. Activity.onDestroy() ● onDestroy() is called when the activity is destroyed ● onDestroy() is the final call the activity receives before it is destroyed by the OS ● onDestroy() is called 1) when the activity is finishing after a call to Activity.finish() or 2) Android OS is destroying the activity to save space ● The hosting process can be killed after this method returns without executing another line of the activitys code, i.e., the hosting process is killablewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 23. Applications in Android Ecosystemwww.youtube.com/vkedco www.vkedco.blogspot.com
  • 24. Security Sandbox ● In computer security, the term sandbox refers to a security mechanism for running program separation ● Security boxes are used to execute untested/untrusted code, e.g., untrusted programs, unsigned/unverified third- parties, untrusted users and websites ● Note: the term untrusted is relative, not absolute ● Sandboxes are typically realized as a set of resources the programs can legally access: disk, memory, network, systems file inspection, etc ● Jail is a set of limits imposed on programs by the OS kernelwww.youtube.com/vkedco www.vkedco.blogspot.com
  • 25. Apps on Android OS ● Android OS is a multi-user Linux system ● Each app is a different user ● Android OS assigns each app a unique Linux user ID ● The user ID is known to the OS but is not known by the app ● The OS sets permissions based on the user ID ● Every application, by default, runs in its own Linux process: the OS starts this process when one of the apps components is executed ● Each process has its own Dalvik JVM: each applications running code runs isolated from other appswww.youtube.com/vkedco www.vkedco.blogspot.com
  • 26. Process Sharing ● Apps may share the same Linux user ID and, consequently, share each others files and resources ● Apps with the same user ID can also request to run in the same Linux process and share the same JVM: this is done when the resources must be conserved ● Apps may request permission to access data stored on the device, e.g., user contacts, Bluetooth, SD card, SMS messages, etc ● All permissions are granted at install timewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 27. Principle of Least Privilege ● PLP principle: Each app has access only to those components that it requires to do its work and no more ● An app cannot access parts of the system for which it is not given permission ● Permissions must be explicitly declared in the manifest filewww.youtube.com/vkedco www.vkedco.blogspot.com
  • 28. References ● http://developer.android.com/reference/android/app/Activity.html ● http://developer.android.com/guide/components/fundamentals.html ● http://developer.android.com/guide/components/processes-and-threads.html ● http://www.linfo.org/process.html ● http://en.wikipedia.org/wiki/Sandbox_(software_development) ● http://en.wikipedia.org/wiki/Sandbox_(computer_security) ● http://www.youtube.com/vkedcowww.youtube.com/vkedco www.vkedco.blogspot.com

×