- Standard: start a activity and add to the top of task stack.
- Single Top: If start an activity with this mode, and system find the top of task stack is this kind acvivity, system will reuse the top activity.(onNewIntent() will be called)
- Single Task: Clear Top is a better name. If start a activity with this mode, and the task stack has already contains this activity, system will clear all the activities above this activity in this stack, and reuse the activity.(onNewIntent() will be called). If start an activity from another application, the activity will start a new task.
- If the activity is in background task, start this activity will bring the task to forground. Please refer to Page.202 of Android群英传
- Single Instance: There is only one such activity in the system, and the task only host this activity. If the activity does not exist, create a task and create the activity to the task. If the activity already exist, just reuse that activity
- Suppose A and C are standard, B is single instance, A start B, B start C, C start B; then click BACK button, C is shown, then click BACK button, A is shown.
To set launch mode, there are two ways:
- In manifest file: <activity android:launchMode=...>
- set intent flags:
- Intent.FLAG_ACTIVITY_NEW_TASK: will start a new task, but this task can also host other activities that start by this activity. If you start an activity within the same application, this flag is ignored (no task will be created)
- Intent.FLAG_ACTIVITY_SINGLE_TOP: same as single top mode.
- Intent.FLAG_ACTIVITY_CLEAR_TOP; same as single task mode.
- Intent.FLAG_ACTIVITY_NO_HISTORY;