Activity Startup Mode and activity

Source: Internet
Author: User

Activity Startup Mode and activity

Activity Startup Mode
Activity has four loading modes:Standard (default), singleTop, singleTask, and singleInstance.
(1). standard (default): Default Loading Method of Activity. Even if an Activity to be started already exists in the Task stack, a new instance is created and pushed to the stack. That is to say, if the Activity in this mode is started, a new instance will be created and pushed to the stack.
For example:
The current stack is a B C D. In the Activity D, jump to D itself through Intent. The current stack situation is: a B C D.
In this case, if the stack top D jumps to B through the Intent, the stack situation is: a B c d B. At this time, if you press the return key in sequence, the stack will pop up in sequence and be displayed on the interface. As shown in:

(2). singleTop Mode: If the Launch mode of an Activity is set to singleTop, when the Activity is located at the top of the stack, it will jump to its own Activity through Intent, A new instance will not be created and pushed into the stack. If the Activity is not at the top of the stack and jumps to the Activity itself through Intent, a new instance is created and pushed to the stack.
For example:
The current stack is a B C D. If the Launch mode of D is set to singleTop, start Intent to jump to D in D, and the stack is still a B C D. However, if the B mode is singleTop at this time, and D jumps to B, because B is not at the top of the stack, the stack situation becomes: a B c d B. For example:

(3). singleTask Mode: If an Activity is in singleTask mode, there will be only one instance of the Activity in the Task stack. All Activity instances on the Activity will be destroyed.
For example, the current stack is a B C D. The Launch mode of B is singleTask. At this time, D jumps to B through Intent, and the stack situation changes to a B. C and D are destroyed, that is, all instances on B are destroyed. For example:

(4). singleInstance Mode: Press Activity into a new job stack. That is to say, the new Activity to be started will be pushed into a new task stack.
For example, the case of Task Stack 1 is a B C. C jumps to D through Intent, and D's Launch mode is singleInstance, a new Task stack 2 will be created. In this case, Task Stack 1 is still a B C. Task Stack 2 is D. At this time, the screen shows the content of D. If D jumps to D through Intent again, no D instance will be created in Task Stack 2, so the situation of the two stacks will not change. If D jumps to C, the situation of stack 1 becomes: a B C, because C's Launch mode is standard. If you press the return key again, stack 1 becomes: a B C. That is to say, the current interface also displays the content of C, not D. For example:

Note:
Differences between singleTask mode and singleInstance mode:
Activity in singleTask mode allows other activities to be part of a task, and it is usually at the root of the task stack. Other activities (the activity must be in standard mode and singleTop Mode) can be loaded to this stack. On the other hand, the activity in singleInstance mode does not allow any other activity to be loaded to this task stack. It is the only activity in the task. If it starts another activity, the activity will be directed to different tasks, which is like marking FLAG_ACTIVITY_NEW_TASK in intent.
(Generally, singleTask startup mode is the same in manifest as FLAG_ACTIVITY_NEW_TASK in intent ).
In general, the singleTask mode can be used in a stack with other activities. All activities above it will be destroyed. The Activity in singleInstance mode is in a single Task.

Related Article

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.