What is the difference between singletop and singletask? (Four loading modes of activity)

Source: Internet
Author: User

Singletop requires that if an instance of the activity to be created at the top of the stack is created when the intent is created, the intent is sent to the instance instead of the new instance. (Note that it is the top stack. You can create a new instance without the top stack !)

Singletask mode: When intent arrives and a singletask activity needs to be created, the system will check whether there are instances of the activity in the stack. If any, send intent directly to it.

Four loading modes of activity:

1. Standard: the default mode of the system. A new instance is generated after one jump. Assume that an activity is named "act1" and the execution statement is as follows:

Startactivity (new intent (act1.this, act1.class ));

Then act1 will jump to another act1, that is, there are two instances of act1 in the current stack. After you press the return key, you will find that it is still in act1 (the first one.

 

2. singletop: singletop is similar to standard mode. The only difference is that when the jump object is the activity at the top of the stack (which should be understood as the activity visible to the user), the program will not generate a new activity instance, instead, it directly jumps to the activity instance that exists at the top of the stack. Take the above example as an example. When act1 is in singletop mode, there is still only one instance in the stack after the jump is executed. If you press the return key, the program will exit directly. This seems to be rarely used.

 

3. singletask: The singletask mode and the singleinstance mode are used to create only one instance. In this mode, the program will not generate a new instance regardless of whether the jump object is in the activity at the top of the stack (the premise is that the instance already exists in the stack ). This mode is quite useful. In the future multi-activity development, multiple instances will be generated on the same page due to the jump relationship, which is always a little poor in user experience, if you declare the corresponding activity as the singletask mode, this problem will no longer exist. However, it seems that I have read it again a while ago. Some people say that we should not set other pages except the start page as singletask.
Mode. The reason is unknown for the moment. Which of the following statements can help you.

 

4. singleinstance: An activity set to singleinstance mode excludes a task (a task can be understood as a process). An activity that exclusively occupies a task is not so much an activity as an application, this application is independent from other activities and has its own context activity. Here is an example:

There are three activities: act1, Act2, and act3. acti2 is in singleinstance mode. The jump relationship between them is: act1 -- Act2 -- act3. Now press the return key in act3. Because Act2 is located in an independent task, it does not belong to the context activity of act3, therefore, act1 is returned directly. This is the singleinstance 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.