Singletop requires that if an instance of the activity to be created at the top of the stack is created when the intent is created, the intent is sent to the instance instead of the new instance. (Note that it is the top stack. You can create a new instance without the top stack !)
Singletask mode: When intent arrives and a singletask activity needs to be created, the system will check whether there are instances of the activity in the stack. If any, send intent directly to it. |
Four loading modes of activity:
1. Standard: the default mode of the system. A new instance is generated after one jump. Assume that an activity is named "act1" and the execution statement is as follows:
Startactivity (new intent (act1.this, act1.class ));
Then act1 will jump to another act1, that is, there are two instances of act1 in the current stack. After you press the return key, you will find that it is still in act1 (the first one.
2. singletop: singletop is similar to standard mode. The only difference is that when the jump object is the activity at the top of the stack (which should be understood as the activity visible to the user), the program will not generate a new activity instance, instead, it directly jumps to the activity instance that exists at the top of the stack. Take the above example as an example. When act1 is in singletop mode, there is still only one instance in the stack after the jump is executed. If you press the return key, the program will exit directly. This seems to be rarely used.
3. singletask: The singletask mode and the singleinstance mode are used to create only one instance. In this mode, the program will not generate a new instance regardless of whether the jump object is in the activity at the top of the stack (the premise is that the instance already exists in the stack ). This mode is quite useful. In the future multi-activity development, multiple instances will be generated on the same page due to the jump relationship, which is always a little poor in user experience, if you declare the corresponding activity as the singletask mode, this problem will no longer exist. However, it seems that some people have read it again a while ago. Generally, do not set other pages except the start page to the singletask mode. The reason is unknown for the moment. Anyone who knows this can ask for help.
4. singleinstance: An activity set to singleinstance mode excludes a task (a task can be understood as a process). An activity that exclusively occupies a task is not so much an activity as an application, this application is independent from other activities and has its own context activity. Here is an example:
There are three activities: act1, Act2, and act3. acti2 is in singleinstance mode. The jump relationship between them is: act1 -- Act2 -- act3. Now press the return key in act3. Because Act2 is located in an independent task, it does not belong to the context activity of act3, therefore, act1 is returned directly. This is the singleinstance mode.
What is the difference between singletop and singletask? (Four loading modes of activity)