The activation mode of the activity is divided into: standard, Singletop, Singletask, singleinstance four kinds.
Standard mode
is the active default startup mode, which is the first contact mode when learning activity jumps. This startup mode ignores the activity at the top of the stack and creates a new activity (even the same activity) after the intent jump is implemented. For example:
Intent intent=new Intent (Firstactivity.this, Firstactivity.class);
StartActivity (Intent);
When you click on firstactivity to trigger a jump, a new firstactivity will be created. A continuous click Trigger jump will continue to stack firstactivity activity in the return stack.
Singletop mode
Modify the startup mode of firstactivity in Androidmanifest.xml in the previous case, adding: android:launchmode= "Singletop". Run again, and when you click on the trigger jump you will notice that the firstactivity activity is no longer created because the firstactivity is already at the top of the stack that returns the stack. This is the feature of the Singletop startup mode: When the activity you want to start is at the top of the current return stack, no new activity will be recreated, but the activity at the top of the stack is used, so firstactivity will only have one instance. However, if you want to start the activity is not at the top of the current return stack, or the same as standard mode, create a new instance, so this is also a singletop problem, singletask the appearance of the problem can be solved.
Singletask mode
When the active startup mode is specified as Singletask, each time the activity is started, the system first checks the return stack for the existence of an instance of the activity. If present, the instance is used directly. Due to the feature of the stack LIFO, if there are other instances of the activity above, the activity will be used to stack all other activities on the activity. If it does not exist, a new activity instance is created.
SingleInstance mode
SingleInstance is one of the most special and complex modes in these four startup modes. SingleInstance applies to situations in which other programs invoke this program activity. Because each program has its own return stack, the same activity in a different return stack into the stack will inevitably create a new instance, using the SingleInstance mode will have a separate return stack to manage the activity, no matter which program to use, will share the same return stack, solve the problem of multi-program sharing. For example, there are currently a, B, c three activities, where the start mode of activity B is singleinstance,a, C is the default standard mode. The active jump process is a->b->c. When you complete the jump from A to C, press the back key in the C interface, you will find that C returns to a, then click the back key, a returns to B. This shows that a and C in the same return stack, a into the stack, c into the same stack. and b enters the other stack. So C returns to a and then clicks back on the A interface, because the stack of a is empty, so the stack top of the other stack is displayed-that is, the stack where B is located, and B is displayed. Then click the Back button, all instances are out of the stack, the program will naturally quit.
android--Active Startup mode