331down voteaccepted
|
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*
|
||||||||||||||||||||
|
Activity have six states
Activity lifecycle have seven methods
Situations
|
||||
The best Demo Application for understanding Activity Life Cycle is here apk file attached. |
|||
There are seven methods that manage the life cycle of an Android application: Answer for what are all these methods for:Let us take a simple scenario where knowing in what order these methods are called will help us give a clarity why they are used.
There are four states an activity can possibly exist:
Starting state involves: Creating a new Linux process, allocating new memory for the new UI objects, and setting up the whole screen. So most of the work is involved here. Running state involves: It is the activity (state) that is currently on the screen. This state alone handles things such as typing on the screen, and touching & clicking buttons. Paused state involves: When an activity is not in the foreground and instead it is in the background, then the activity is said to be in paused state. Stopped state involves: A stopped activity can only be bought into foreground by restarting it and also it can be destroyed at any point in time. The activity manager handles all these states in such a way that the user experience and performance is always at its best even in scenarios where the new activity is added to the existing activities |
||||
From the Android Developers page, onPause():
onStop():
Now suppose there are three Activities and you go from A to B, then onPause of A will be called now from B to C, then onPause of B and onStop of A will be called. The paused Activity gets a Resume and Stopped gets Restarted. When you call I hope it's clear enough. |
|||||||||||||
|
The entire confusion is caused since Google chose non-intuivitive names instead of something as follows:
The Activity Diagram can be interpreted as: |
|||||||||||||||||||||
|