Reference article:
Http://developer.android.com/guide/topics/manifest/activity-element.html#lmodehttp://www.cnblogs.com/hnrainll/archive/2012/12/18/2823064.html
Activity has four startup modes: Standard, Singletop, Singletask, SingleInstance. To understand them, first look at the concept of application, Activity Stack, and task.
First, application, Activity Stack, Task
1, application is an application (APK).
2, activity stack, that is, activity stacks, follow the advanced principle, the system only shows the activity at the top of the stack.
3, Task, combine multiple activity together, these activity can belong to different application.
Second, Launchmode-start mode
Introduction to Official information : Launchmode is used to indicate how activity starts. When the ACTIVITY starts, it is determined by the flags (flag_activity_* constant) in intent. The default is standard.
These four startup modes are divided into two factions, Standard and Singletop faction, Singletask and SingleInstance faction. Standard and Singletop initiated activity can have multiple instances, which can belong to any task and can exist anywhere in the activity stack. The typical usage for initiating activity in a task that uses standard and Singletop modes is startactivity (). If the intent object contains a flag_activity_new_task declaration, a new task is started, see the taskaffinity property for details.
Singletask and SingleInstance start the activity with a new task. The activity that starts is always at the bottom of the activity stack. Also, the system can only hold one instance object of the activity, that is, there can be only one task.
The only difference between standard and singletop mode is that whenever a new intent tries to start the standard activity, a new activity instance is created to respond to the intent, Each activity instance holds a intent object. Similarly, when there is a new intent object to start the singletop activity, a new activity instance is created to handle the intent. However, if the task has an activity instance that is trying to start, and at the top of the stack, the activity receives the intent (using the Onnewintent () method), and the new instance is not created. In other cases, such as the presence of singletop activity in a task, but not at the top of the stack, or not at the top of the stack on the target stack, a new instance is created in the stack.
Similarly, how to react depends on the startup mode of the parent interface, by clicking the Back button. If the parent activity is singletop (or intent contains flag_activity_clear_top flag), the parent activity will be moved to the top of the stack. Navigation intent will be received by the parent activity's onnewintent () method. If the activation mode of the parent activity is standard (and there is no flag_activity_clear_top flag in intent), the current activity and its parent activity are removed from the stack, A new parent activity is then created to receive the navigation intent.
The only difference between the Singletask and SingleInstance modes is that the singletask activity is always at the bottom of the task and allows other activity to join its task. SingleInstance activity, on the other hand, does not allow other activity to join its task, which is the only activity in the task, and if other activity is started, it will be started in different tasks. It's like using intent to pass Flag_activity_new_task flag.
| Use Cases |
Launch Mode |
Multiple Instances? |
Comments |
| A common starting mode for many activity |
Standard |
Yes |
The default. The system always creates the activity in that way in the task and passes the intent object to it. |
| Singletop |
Subject to availability |
There is an instance of activity in the target task, and the system passes the intent object through the Onnewintent () method instead of creating a new instance. |
Specialized launches (not recommended) |
Singletask |
No |
Create an activity instance at the bottom of the new task and pass the intent. However, if an instance already exists for the activity, the system passes the intent object through Onnewintent () instead of creating a new instance. |
| SingleInstance |
No |
The same as Singletask, except that the system does not run other activity in the task where the activity is located. The activity is the only activity instance in the task in which it is located. |
Write a code test later, and then update.
Activity startup mode