First of all, we must know that activity is managed in a stack (LIFO) structure.
When activity a starts activity B, a is pressed into the stack, and B is at the top level of the stack. When B calls finish () to end the activity, B pops up from the stack, at which point A is at the top level of the stack.
We can implement the change of the startup mode by specifying the android:launchmode= "standard" property in the Activity node of the Androidmanifest.xml file.
Well, to understand how the activity is managed, let's get to know the 4 startup modes of the activity.
1:stand
This standard boot mode is used if you do not specify a startup mode. For example, if we start activity A, the a,a will be re-created and pressed into the stack, regardless of whether the stack is already present.
2:singletop
The top level activity is unique. For example, if we start activity A, if a is already present at the top of the stack, then use a directly.
3:singletask
The only activity in the stack. and 2 The biggest difference is that this mode regardless of where you live on the stack, as long as the start a is found in the stack, the activity on A is all destroyed (life cycle such as ondestory will also be executed), directly using a
4:singleinstance
Create a new stack to manage this activity.
For example, we specify the active B boot mode to SingleInstance, a, c default to use stand, and a, B, C, to start three activities:
C Activity Finish (), the return is a (instead of B, because the stack of management B is independent of AC); a activity finish (), then the current stack is empty, and then found the other stack (that is, the stack where activity B resides).
Introduction to the 4 startup modes of "Android" activity