1. return stack concept
2. Life cycle
1. OnCreate ()
You have seen this method many times, and we have rewritten this method in each activity, and it will be called when the activity is first created. You should perform initialization of activities in this method, such as loading layouts, binding events, and so on.
2.onStart ()
This method is called when the activity becomes visible from invisible.
3.onResume ()
This method is called when the activity is ready to interact with the user. The activity at this point must be at the top of the stack that is returned and is in a running state.
4. OnPause ()
This method is called when the system is ready to start or resume another activity. We usually release some CPU-consuming resources in this method and save some key data, but this method must be executed quickly, otherwise it will affect the use of the new stack top activity.
5. OnStop ()
This method is called when the activity is completely invisible. The main difference between it and the OnPause () method is that if the new activity started is a dialog-box activity, then the OnPause () method will be executed, and the OnStop () method will not execute.
-
OnDestroy ()
This method is called before the activity is destroyed, and then the state of the activity becomes the destroy state.
-
Onrestart ()
This method is called before the activity is changed from the stopped state to the running state, i.e. the activity is restarted.
3. Activity status
Each activity may have a maximum of four states in its life cycle.
1. Operational status
When activity is displayed in the foreground, the activity is in active state or running state 2. Paused When an activity loses focus is still visible, the activity is paused (that means a new not full-screen or transparent activity is in front of the activity and gets the focus.) ) 3. Stopped If an activity is completely blocked by another activity, it goes into a stopped state. 4. Shutdown
When an activity is removed from the return stack, it becomes a destroyed state. The system will most likely recycle activities in this State, thus ensuring that the phone has sufficient memory.
4. Active startup mode
Standardsingletopsingletasksingleinstance
You can select the startup mode by assigning the Android:launchmode property to the <activity> tag in Androidmanifest.xml
Standard is the active default startup mode, which is automatically used by all activities without explicit designation.
In standard mode (that is, by default), whenever a new activity is started, it is placed in the stack on the return stack and at the top of the stack. For activities that use standard mode, the system does not care if the activity is already present in the return stack, and a new instance of the activity is created each time it is started.
Singletop
Singletop, when you start an activity, if you find that the stack at the top of the return stack is already the activity, you think you can use it directly and no longer create a new activity instance.
Singletask
Singletask, each time the activity is started, the system first checks to see if there is an instance of the activity in the return stack, uses the instance directly if found to exist, and puts all the activities on top of the activity out of the stack, creating a new instance of the activity if no discovery is made.
SingleInstance
SingleInstance mode activity will enable a new return stack to manage this activity
Android03-activity life cycle and startup mode