Android Note (eight) active startup mode

Source: Internet
Author: User

1. There are four boot modes, standard, Singletop, Singletask, and singleinstance, which can be assigned to the activity tag in Androidmanifest.xml by Android: The Launchmode property to select the startup mode.

2.standard
Standard is the active default startup mode, and all activities are automatically used without explicit designation
This startup mode. In standard mode, whenever a new activity is started, it is placed in the stack on the back of the stack and at the top of the stack. For activities that use standard mode, the system does not care if the activity is already present in the return stack, and a new instance of the activity is created each time it is started. For example, now the top of the stack activity is 1, you on the basis of 1 to restart Activity 1, then now the stack is two levels of activity, the first layer is the activity 1, the second layer or the activity 1.

3.singleTop
When the active startup mode
Specified as Singletop, if the top of the stack is found to be the activity at the start of the activity, it is considered straightforward to use and no new activity instance is created. However, when the activity is not at the top of the stack, the activity is started again, and a new instance is created.

4.singleTask
When the active startup mode is specified as Singletask, each time the activity is started, the system first checks to see if there is an instance of the activity in the return stack, uses the instance directly if the discovery already exists, and puts all the activities on top of the activity out of the stack, creating a new instance of the activity if no discovery is found.
Start activity 2 on the basis of activity 1, and then start Activity 1, you will find that activity 1 already exists in the return stack, so activity 2 will be out of the stack, activity 1 back to the top of the stack activity. During this period, activity 1 executed the Onrestart () method, and activity 2 executed the Ondestory () method.

5.singleInstance
The activity initiated by SingleInstance mode enables a new return stack to manage this activity. Suppose we have an activity in our program that allows other programs to call, and if we want to implement other programs and our programs can share an instance of this activity, how do we do that? Using the previous three startup modes is definitely not going to work because each application will have its own return stack, and a new instance must be created when the same activity is stacked on a different return stack. Using the SingleInstance mode can solve this problem, in this mode there will be a separate return stack to manage the activity, regardless of which application to access the activity, the same return stack shared, also resolves the problem of shared activity instances.
For example, we now turn on activity 1, Activity 2, Activity 3, and Activity 2 start mode is singleinstance, now activity 1 and Activity 3 are in the same return stack, and activity 2 is on the other return stack, and there is only one activity in this stack.

Now, the mobile phone shows the activity 3, we press the Back button, the mobile phone is the activity 1, in the press the Back button, the opportunity to display the activity 2, press the return key again before exiting the program.
Because only one return stack is empty, another stack top activity that returns the stack is displayed.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Note (eight) active startup mode

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.