1. Task is a stack that contains a series of activity, followed by the advanced post-out principle.
2. Task default behavior:
(1) Premise: Activity A and Activity B are in the same application.
Action: Activity A starts the secluded task stack (stack state: A), starts activity B (stack State: AB) in activity A, and presses the back return key (stack state: a).
(2) Premise: Activity A and Activity B in the same application, the application name is "TaskOne application".
Action: Click the TaskOne app icon in launcher, Activity A launches the secluded task stack, named Taska (Taska stack State: A),
Start Activity B (Taska stack Status: AB) in activity A, press and hold the home key, return to launcher, launch other applications (e.g. ebook),
Open secluded a new task stack, name: TASKB, press and hold home, return to launcher, click the TaskOne app icon, and the Taska stack returns to the foreground.
Activity B is a top-of-the-stack application for user use.
(3) Premise: Activity A in the name "TaskOne application" in the application, activity C in the name of "Tasktwo application" in the application.
Action: Click the TaskOne app icon in launcher, Activity A launches the secluded task stack, named Taska (Taska stack State: A),
Start Activity C (Taska stack Status: AC) in activity A, press and hold the home key, return to launcher, launch "Tasktwo app" i.e. activity C,
Open the secluded new task stack, name TASKB, press the back key to return to launcher, click the TaskOne app icon, and the Taska stack returns to the foreground.
Activity c is a top-of-the-stack application for user use.
3. Intent Flag Introduction:
(1) Flag_activity_new_task: Set this state, keeping in mind the following principles, first to find out if there is a task stack with the same affinity for the ACTIVITY being started (i.e. taskaffinity, Note that the affinity of the activity in the same application, so the following a case will be in the same stack, the preceding sentence is a bit awkward, please read a few times, if there is, just directly put this stack to the foreground, and keep the state of the stack unchanged, that is, the activity sequence in the stack unchanged, if there is no , a new stack is created to hold the activated activity
A. Prerequisites: Activity A and Activity B are in the same application.
Action: Activity A starts the secluded task stack (stack state: A), starts activity B in activity A, and the flag of intent that initiates activity B is set to
Flag_activity_new_task, activity B is pressed into the stack (stack state: AB) where activity A is located.
Cause: By default, all activity in an app has the same relationship (taskaffinity).
B. Prerequisites: Activity A in an application named "TaskOne Application", activity C and Activity D are in an application named "Tasktwo app".
Action 1: Click the TaskOne app icon in launcher, Activity A launches the secluded task stack, named Taska (Taska stack State: A),
Starting activity C in activity A, the flag for intent with activity C is set to Flag_activity_new_task,
The Android system will open secluded a new task for activity C, named TASKB (TASKB stack State: C), press and hold the Home key, select Taska,
Activity a returns to the foreground and starts activity C again (two cases 1. starting from the desktop; 2. Starting from Activity A, as in both cases), when TASKB returns to the foreground, activity c is displayed for use by the user, i.e.:
A task that contains Flag_activity_new_task's intent start activity is running, and no new task is created for that activity.
Instead, the original task is returned to the foreground display.
Action 2: Click the TaskOne app icon in launcher, Activity A launches the secluded task stack, named Taska (Taska stack State: A),
Starting activity C in activity A, the flag for intent with activity C is set to Flag_activity_new_task,
The Android system will open secluded a new task for activity C, named TASKB (TASKB stack State: C), starting in activity C
Activity D (TASKB Status: CD) long Press the Home key, select Taska, activity a back to the foreground, start activity C again (starting from the desktop or Activitya, is the same),
At this time TASKB back to the front desk, Activity D is displayed for the user to use. After setting the Flag_activity_new_task in this case, it will first find out if there is a stack with Activity C, according to Affinity (taskaffinity) , if any, just move the stack to the foreground, and keep the state of the stack unchanged, that is, the order in the stack is unchanged.
(2) Flag_activity_clear_top:
Premise: Activity A, activity B, activity C and Activity D are in the same application.
Action: Activity A starts the secluded task stack (stack state: A), starts activity B in activity a (stack state: AB), starts in activity b
Activity C (Stack state: ABC), start activity D (Stack state: ABCD) in activity C, start activity B in Activity D,
The flag of intent that initiates ACTIVITY B is set to Flag_activity_clear_top, (stack state: AB).
(3) Flag_activity_brought_to_front:
If activity A is in an application named "TaskOne Application", activity C and Activity D are in an application named "Tasktwo app".
Action: Click the TaskOne app icon in launcher, Activity A launches the secluded task stack, named Taska (Taska stack State: A),
Starting activity C in activity A, the flag for intent with activity C is set to Flag_activity_new_task,
The Android system will open secluded a new task for activity C, named TASKB (TASKB stack State: C), starting in activity C
Activity D (Stack state of TASKB: CD), press and hold the Home key, select Taska, activity a returns to the foreground and activity C is activated again in activity a.
Set flag to Flag_activity_brought_to_front in intent starting ACTIVITY C, taskb back to the foreground,
Activity C shows, (TASKB stack state: C).
(4) Flag_activity_multiple_task:
Used in conjunction with Flag_activity_new_task, first set flag_activity_new_task in intent, open ACTIVITY,
Starts a new task, then sets Flag_activity_multiple_task in intent and opens the same ACTIVITY again, and a new task is started.
(5) Flag_activity_single_top:
There is an ABCD four activity in the current task stack, a is the top activity of the stack, and D is the bottom of the stack activity, which is set in the intent of open a
Flag_activity_single_top flag, the stack top A is used instead of the new new A.
(6) Flag_activity_reset_task_if_needed:
Typically used in conjunction with Flag_activity_clear_when_task_reset, if this property is set, the ACTIVITY will start in a new task or be taken to the top of an already existing task, The activity will then be loaded as the first page of the task. Will cause a task with the same affinity to the application to be in a suitable state (move activity to or from this task), or simply reset the task to its initial state
Flag_activity_clear_when_task_reset: Sets a restore point in the current TASK stack when a intent request with flag_activity_reset_task_if_needed starts the stack ( A typical example is when the user starts the app again from the desktop, and the restore point includes the application that will be erased. Application scenario: In the email program preview the picture, will start the picture viewing actvity, when the user leaves the email processing other things, and then next time from home to enter the email, we present to the user should be the last email session, not the picture viewing, This will not cause confusion to users.
Example: There is activity a, activity B, activity C, activity A starts the secluded task stack, named Taska (Taska stack State: A),
Start activity B (Taska stack state: AB) in activity A, then activity B starts Activity C (Taska stack State: ABC),
Start ACTIVITY C by setting the Flag_activity_clear_when_task_reset title in the intent so that there is a restore point in the Taska
When there is a intent request Taska stack that contains flag_activity_reset_task_if_needed (e.g. request ACTIVITY A)
The system will clear the activity above the restore point, and only AB is left on the Taska stack.
4. Launchmode Introduction:
(1) Standard:
If the FLAG_ACTIVITY_NEW_TASK flag is not set in the intent that initiates this activity, the activity is in the same task as the activity that initiated it,
If the ACTIVITY is set, please refer to the above flag_activity_new_task for details, "Launchmode" is set to "standard"
The activity can be instantiated several times, and it can be instantiated at any point in the task for a new intent request.
(2) Singletop:
If the FLAG_ACTIVITY_NEW_TASK flag is not set in the intent that initiates this activity, the activity is in the same task as the activity that initiated it,
If you set up activity please refer to the above flag_activity_new_task details, "Launchmode" set to "singletop" activity can be
Instantiated multiple times, can be anywhere in a task, for a new intent request if at the top of the task stack, the activity intent request at the top of the stack is used,
Instead of instantiating the object to receive the request, if it is not at the top of the stack, a new object is instantiated to receive the intent request.
(3) Singletask:
The activity of "Launchmode" set to "Singletask" is always at the bottom of the stack and can only be instantiated once, allowing other activity to be pressed into the "singletask" activity
On the task stack, if there is a new intent request for activity with this flag, the system clears all activity in the task stack with this flag and displays the activity.
(4) SingleInstance:
Launchmode "singleinstance" activity is always at the bottom of the stack, can only be instantiated once, do not allow other activity to press "SingleInstance"
Activity on the task stack, which is the only activity in the entire task stack.
5. Taskaffinity Properties:
(1) The taskaffinity attribute should be used in conjunction with the FLAG_ACTIVITY_NEW_TASK flag and the allowtaskreparenting attribute, if only the taskaffinity attribute is used,
Please refer to the default behavior of the task above.
(2) combined with the Flag_activity_new_task logo:
A. Title: Activity A and Activity B in the same application, activity A and Activity B set different taskaffinity properties.
Action: Activity A starts the secluded task stack, named Taska (Taska stack State: A), starts activity B in activity A, starts activity b
Intent set the FLAG_ACTIVITY_NEW_TASK flag, the system will open secluded a task stack, TASKB (TASKB stack State: B).
B. Title: Activity A In "TaskOne application", Activity C in "Tasktwo app", activity A and ACTIVITYC set the same taskaffinity attribute.
Action: Activity A starts the secluded task stack, named Taska (Taska stack State: A), launches activity C in activity A, initiates activity C
When the FLAG_ACTIVITY_NEW_TASK flag is set in intent, activity C presses into the same Taska stack as the activity a stack (Taska stack state: AC).
(3) with allowtaskreparenting properties:
Example: In "TaskOne app" There is a weather report activity A, activity a and other activity in the "TaskOne app" have a default relationship
(The Taskaffinity property is not set), and the Allowtaskreparenting property is set to True, there is now a "Tasktwo app
"Launch the weather report in the TaskOne app" activity A, when activity A is in the same task as the activity in the "Tasktwo app",
The task stack is named Taska, when the "TaskOne application" starts and the weather forecast activity A is developed, and activity A is transferred from the Taska stack to
The stack where the "TaskOne app" is located, where activity a can be moved back and forth across multiple stacks.
6. Alwaysretaintaskstate Properties:
If root activity in the task stack sets this property value to true, the status of the activity in the task stack is preserved regardless of any situation.
7. Cleartaskonlaunch Properties:
If the root activity in the task stack sets this property value to True, the system will immediately clean up all activity except root activity as soon as you leave the task stack.
8. Finishontasklaunch Properties:
If an activity sets the Finishontasklaunch property, the system clears the activity as soon as you leave the task stack,
Regardless of whether the activity is anywhere on the stack.
Reprint: http://www.cnblogs.com/xiaoQLu/archive/2012/07/17/2595294.html
Android Boot Tag