http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for
Android activity life cycle - what are all these methods for?
153
130
|
What is the life cycle of an Android activity? Why are so many similar sounding methods (
onCreate() , onStart() , onResume() ) called during initialization, and so many others (onPause() , onStop() , onDestroy() ) called at the end?
When are these methods called, and how should they be used properly?
| ||||||||||||||||
|
345
|
See it in Activity Lifecycle (at Android Developers).
When the Activity first time loads the events are called as below:
When you click on Phone button the Activity goes to the background and the below events are called:
Exit the phone dialer and the below events will be called:
When you click the back button OR try to finish() the activity the events are called as below:
The Android OS uses a priority queue to assist in managing activities running on the device. Based on the state a particular Android activity is in, it will be assigned a certain priority within the OS. This priority system helps Android identify activities that are no longer in use, allowing the OS to reclaim memory and resources. The following diagram illustrates the states an activity can go through, during its lifetime:
These states can be broken into three main groups as follows:
Active or Running - Activities are considered active or running if they are in the foreground, also known as the top of the activity stack. This is considered the highest priority activity in the Android Activity stack, and as such will only be killed by the OS in extreme situations, such as if the activity tries to use more memory than is available on the device as this could cause the UI to become unresponsive.
Paused - When the device goes to sleep, or an activity is still visible but partially hidden by a new, non-full-sized or transparent activity, the activity is considered paused. Paused activities are still alive, that is, they maintain all state and member information, and remain attached to the window manager. This is considered to be the second highest priority activity in the Android Activity stack and, as such, will only be killed by the OS if killing this activity will satisfy the resource requirements needed to keep the Active/Running Activity stable and responsive.
Stopped - Activities that are completely obscured by another activity are considered stopped or in the background. Stopped activities still try to retain their state and member information for as long as possible, but stopped activities are considered to be the lowest priority of the three states and, as such, the OS will kill activities in this state first to satisfy the resource requirements of higher priority activities.
Sample activity to understand the life cycle*
| ||||||||||||||||||||
|
67
|
The entire confusion is caused since Google chose non-intuivitive names instead of something as follows:
The Activity Diagram can be interpreted as:
| ||||||||||||||||||||
|