Task and activity details

Source: Internet
Author: User

1. A task is a stack that contains a series of activities and follows the advanced post-release principle.

 

2. Default task behavior:

 

(1) premise: Activity A and Activity B are in the same application.

 

Operation: Activity A starts the uncommon Task Stack (stack status: a), starts Activity B (stack status: AB) in Activity A, and presses the back return key (stack status: ).

 

(2) premise: Activity A and Activity B are in the same application, and the Application name is "taskone application ".

 

Operation: click the "taskone application" icon in the launcher. Activity A starts the uncommon Task Stack and name it TASKA (TASKA stack status: ),

Start Activity B (TASKA stack status: AB) in Activity A, long press the Home Key, return launcher, and start other applications (such as e-books ),

Open a new task stack named taskb and press home to return to launcher. Click the "taskone application" icon. At this time, the TASKA stack will return to the foreground,

Activity B is the top stack application for users.

 

(3) premise: Activity A is in an application named "taskone application", and activity C is in an application named "tasktwo application.

 

Operation: click the "taskone application" icon in the launcher. Activity A starts the uncommon Task Stack and name it TASKA (TASKA stack status: ),

Start Activity C (TASKA stack status: Ac) in Activity A, press the Home Key, return launcher, and start "tasktwo application", that is, Activity C,

Open a new task stack and name it taskb. Press the back key to return to launcher and click the "taskone application" icon. At this time, the TASKA stack will return to the foreground,

Activity B is the top stack application for users.

 

3. Intent flag introduction:

 

(1) flag_activity_new_task:

 

A. premise: Activity A and Activity B are in the same application.

 

Operation: Activity A starts the uncommon Task Stack (stack status: a), starts Activity B in activity A, and sets the flag of the intent that starts Activity B

Flag_activity_new_task: Activity B is pushed to the stack where activity A is located (stack status: AB ).

 

Cause: by default, all the activities in the same application have the same relationship (taskaffinity ).

 

B. premise: Activity A is in the application named "taskone application", and activity C and Activity D are in the application named "tasktwo application.

 

Operation 1: click the "taskone application" icon in the launcher. Activity A starts the uncommon Task Stack and name it TASKA (TASKA stack status: ),

Start Activity C in activity A and set the flag of intent of Activity C to flag_activity_new_task,

The Android system will open a new task for Activity C and name it taskb (taskb stack status: C). Press the Home Key and select TASKA,

Activity A returns to the foreground and starts Activity C again. At this time, taskb returns to the foreground. Activity C is displayed for users to use, that is:

If the intent that contains flag_activity_new_task starts the activity and the task is running, no new task is created for the activity,

Instead, the original task is returned to the foreground for display.

 

Operation 2: click the "taskone application" icon in the launcher. Activity A starts the uncommon Task Stack and name it TASKA (TASKA stack status: ),

Start Activity C in activity A and set the flag of intent of Activity C to flag_activity_new_task,

The Android system will open a new task for Activity C, named taskb (taskb stack status: C), started in Activity C

Activity D (taskb status: CD) Long press the Home Key, select TASKA, activity a returns to the foreground, start Activity C again,

At this time, taskb is returned to the foreground, and activity D is displayed for your use.

 

(2) flag_activity_clear_top:

 

Premise: Activity A, Activity B, Activity C, and activity D are in the same application.

 

Operation: Activity A starts an uncommon Task Stack (stack status: a), activity B (stack status: AB) in Activity A, and activity B.

Activity C (stack status: ABC), start Activity D (stack status: ABCD) in Activity C, and start Activity B in Activity D,

Set the flag of intent of Activity B to flag_activity_clear_top (stack status: AB ).

 

(3) flag_activity_brought_to_front:

 

Prerequisite: Activity A is in an application named "taskone application", and activity C and Activity D are in an application named "tasktwo application.

 

Operation: click the "taskone application" icon in the launcher. Activity A starts the uncommon Task Stack and name it TASKA (TASKA stack status: ),

Start Activity C in activity A and set the flag of intent of Activity C to flag_activity_new_task,

The Android system will open a new task for Activity C, named taskb (taskb stack status: C), started in Activity C

Activity D (stack status of taskb: CD), long press the Home Key, select TASKA, activity a returns to the foreground, and start Activity C again in activity,

Set flag to flag_activity_brought_to_front in intent of Activity C, and taskb will return to the foreground,

Activity C display (stack status of taskb: C ).

 

(4) flag_activity_multiple_task:

 

Used in combination with flag_activity_new_task. First, set flag_activity_new_task in intent to open the activity,

Start a new task, set flag_activity_multiple_task in intent, and start the same activity again.

 

(5) flag_activity_single_top:

 

There are four activities in the current task stack: ABCD, A is the top activity of the stack, D is the bottom activity of the stack, and A is set in the intent that opens

The flag_activity_single_top flag will use stack top a instead of new.

 

(6) flag_activity_reset_task_if_needed:

 

For example, Activity A, Activity B, Activity C, and activity a start an uncommon Task Stack and name it TASKA (TASKA stack status: ),

Start Activity B (TASKA stack status: AB) in Activity A, and then Activity B starts Activity C (TASKA stack status: ABC ),

Set the flag_activity_clear_when_task_reset title in the intent of Activity C, so that there is a restore point in TASKA,

When an intent request for the TASKA stack contains flag_activity_reset_task_if_needed (for example, requesting activity)

The system will clear the activity above the Restore Point, and only AB is left in the TASKA stack.

 

4. launchmode introduction:

 

(1) Standard:

 

If the flag_activity_new_task flag is not set in the intent that starts the activity, the activity is in the same task as the activity that starts the activity,

If the activity is set, refer to the previous release description of flag_activity_new_task, and set "launchmode" to "standard ".

The activity can be instantiated multiple times and can be instantiated at any position in the task for a new intent request.

 

(2) singletop:

 

If the flag_activity_new_task flag is not set in the intent that starts the activity, the activity is in the same task as the activity that starts the activity,

If the activity is set, refer to the previous release description of flag_activity_new_task. The activity with "launchmode" set to "singletop" can be

The instance is instantiated multiple times and can be anywhere in the task. If a new intent request is at the top of the task stack, the intent request will be reflected by the activity at the top of the stack,

Instead of re-instantiating an object to receive requests, if not at the top of the stack, a new object will be instantiated to receive intent requests.

 

(3) singletask:

 

The activity with "launchmode" set to "singletask" is always at the bottom of the stack and can only be instantiated once. It allows other activities to be pushed to the activity of "singletask ".

In the task stack, if a new intent request has an activity with this identifier, the system will clear all the activities in the task stack with this identifier and display the activity.

 

(4) singleinstance:

 

The activity with launchmode set to "singleinstance" is always at the bottom of the stack and can only be instantiated once. Other activities are not allowed to be pushed to "singleinstance"

In the task stack, that is, the entire task stack can only have such an activity.

 

5. taskaffinity attributes:

 

(1) The taskaffinity attribute should be used in combination with the flag_activity_new_task flag and allowtaskreparenting attribute. If you only use the taskaffinity attribute,

Refer to the default actions of the preceding task.

 

(2) combined with the flag_activity_new_task flag:

 

A. Prerequisites: Activity A and Activity B are in the same application. Activity A and Activity B set different taskaffinity attributes.

 

Operation: Activity A starts the uncommon Task Stack, named TASKA (TASKA stack status: a), starts Activity B in activity A, and starts Activity B

Set the flag_activity_new_task flag in intent. In this case, the system will open a new task stack, taskb (taskb stack status: B ).

 

B. Prerequisites: Activity A is in the "taskone application", Activity C is in the "tasktwo application", and activity A and activityc set the same taskaffinity attribute.

 

Operation: Activity A starts an uncommon Task Stack named TASKA (TASKA stack status: a), starts Activity C in activity A, and starts Activity C's

Set the flag_activity_new_task flag in intent. At this time, Activity C will press the TASKA stack (TASKA stack status: Ac) that is the same as activity a stack ).

 

(3) attributes with allowtaskreparenting:

 

For example, in the "taskone application", there is a weather forecast activity A. Activity A has a default relationship with other activities in the "taskone application ".

(The taskaffinity attribute is not set), and The allowtaskreparenting attribute is set to true. Now there is a "tasktwo Application

Activity A in the "taskone application" is started. At this time, Activity A and activity in the "tasktwo application" are in the same task,

The task stack is named TASKA. At this time, the "taskone application" is started and the weather forecast activity A is developed. At this time, Activity A is transferred from the TASKA stack

The stack of the "taskone application", that is, Activity A can be transferred back and forth among multiple stacks.

6. alwaysretaintaskstate attributes:

 

If the value of this attribute is set to true for the root activity in the task stack, the status of the activity in the task stack is retained no matter what happens.

 

7. cleartaskonlaunch attributes:

If the value of this attribute is set to true for the root activity in the task stack, as soon as you exit the task stack, the system will immediately clear all the activities except the root activity.

 

8. finishontasklaunch attributes:

 

If a finishontasklaunch attribute is set for an activity, the system will immediately clear the activity as soon as you exit the task stack,

Regardless of the location of the activity in the stack.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.