four startup modes for activity
Standard, Singletop, Singletask, SingleInstance
In Androidmanifest configuration:
<activity android:name= ". Mainactivity "android:launchmode=" standard "/>
<activity android:name=". Mainactivity "android:launchmode=" Singletop "/>
<activity android:name=". Mainactivity "android:launchmode=" Singletask "/>
<activity android:name=". Mainactivity "android:launchmode=" SingleInstance "/>
The default mode is standard standard mode, where multiple instances of the same activity are created and placed on the task stack in accordance with the advanced principle one by one.
when we press the back key, we remove the activity from the task stack. Standard default standard mode
The default activity is standard standard mode, and multiple instances are created when the same activity is started multiple times, in this mode,
who initiates the activity of the pattern, which is part of the task stack that initiates it
As in the stack:
Standardactivity->standardactivity->standardactivity
Out Stack:
Standardactivity->standardactivity->standardactivity
Each time a new instance is created, but all are in the same task stack, click the Back key exit, according to the advanced principle out of the stack. singletop Stack top multiplexing mode when the stack has no singletopactivity instance, as with standardactivity, the lifecycle approach goes when there are singletopactivity instances in the stack and at the top of the stack, StartActivity again, instead of creating a new instance, reusing the top singletopactivity instance of the stack and simply callback the Onnewintent method and accept intent object delivery when there are singletopactivity instances in the stack, But not at the top of the stack, once again startactivity, like standardactivity, life-cycle methods are gone
such as startup Mode 1:
Standardactivity->singletopactivity->singletopactivity->singletopactivity
Out Stack:
Singletopactivity->standardactivity
Because the top element of the stack is singletopactivity, it will be reused without creating the Singletopactivity instance again
As in stack: 2:
standardactivity->singletopactivity->standardactivity->singletopactivity
Out stack:
Singletopactivity->standardactivity->singletopactivity->standardactivity singletask in-stack reuse mode if the stack does not exist, the first time you start singletaskactivity, you take the life cycle of the activity, create a new task, and push the activity into the stack, and then start the singletaskactivity again:
If Singletaskactivity is on the top of the stack and does not create more than one instance, it will reuse the instance and only callback the Onnewintent method and accept the intent object delivery If the singletaskactivity is not located on the top of the stack, the activity instance above it is cleared from the stack, and not multiple instances are created, but the instance is reused, and only the Onnewintent method is invoked and the intent object is passed if the stack exists When you first start singletaskactivity, you take the life cycle of the activity and push the singletaskactivity instance into this stack, and then start singletaskactivity again:
If Singletaskactivity is on the top of the stack, it does not create multiple instances, but instead uses this instance and only recalls the Onnewintent method and accepts intent object delivery If Singletaskactivity is not at the top of the stack, the activity instance above it is cleared from the stack, and not multiple instances are created, but instead the instance is reused, and only the Onnewintent method is invoked and the intent object is passed the
such as startup Mode 1:
Standardactivity->singletaskactivity->singletaskactivity->singletaskactivity
Out Stack:
Singletaskactivity->standardactivity
Because the Singletaskactivity instance is finally started, the instance created earlier is reused and the above element is cleared out of the stack
such as startup Mode 2:
Standardactivity->singletaskactivity->singletopactivity->singletaskactivity
Out Stack:
Singletaskactivity->standardactivity
such as startup mode 3:
Singletaskactivity->standardactivity->singletopactivity->singletaskactivity
Out Stack:
Singletaskactivity singleinstance globally unique mode
Standardactivity singletopactivity singletaskactivity These three startup modes are generally in and out of a stack, while the Singleinstanceactivity class compares the cows, Is that it will occupy a single stack, with global uniqueness, the entire mobile phone system on this instance, if there is reuse, if not present, new.
Mobile phone back key is the stack of advanced after the order out of the stack, but Singleinstanceactivity is a separate stack, so the stack order needs to be designed well.
If initiator: 1:
Standardactivity->singletopactivity->singleinstanceactivity->singletaskactivity
Out Stack:
Singletaskactivity->singletopactivity->standardactivity->singleinstanceactivity
Because the standardactivity singletopactivity singletaskactivity three instances in a stack, the need to all out, before it will turn to the singleinstanceactivity on the stack of elements out of the stack
such as startup Mode 2:
Standardactivity->singletopactivity->singletaskactivity->singleinstanceactivity
Out Stack:
Singleinstanceactivity->singletaskactivity->singletopactivity->standardactivity
such as startup mode 3:
Singletaskactivity->singletopactivity->singleinstanceactivity->singletaskactivity
Out Stack:
Singletaskactivity->singleinstanceactivity