[Android Basics] activity startup mode (Android: launchmode)

Source: Internet
Author: User

 

In Android, there are four activity startup modes:

"Standard" (default)

"Singletop"

"Singletask"

"Singleinstance"

 

They are mainly different in the following ways:

 

1. How to Determine the task

The target task of the activity of "standard" and "singletop" is in the same task as the receiver of the received intent, unless the Intent includes the flag_activity_new_task parameter.

If the flag_activity_new_task parameter is provided, it is started into another task.

"Singletask" and "singleinstance" always regard activity as the root element of a task and they will not be started into another task.

 

The description is incorrect. Thanks to liuluxu1989.

This blog post is relatively simple and does not contain any diagrams. You cannot understand it. You can directly read the dev guide or the following blog post:

Http://marshal.easymorse.com/archives/2950

 

2. Whether multiple instances are allowed

"Standard" and "singletop" can be instantiated multiple times and exist in different tasks. A task can contain multiple instances of one activity;

"Singletask" and "singleinstance" only generate one instance and are the root element of the task.

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.

 

3. Whether other activities are allowed to exist in this task

"Singleinstance" exclusively occupies a task, and other activities cannot exist in that task. If it starts a new activity, no matter what the launch mode of the new activity is, all new activities will be run in other tasks (as if the flag_activity_new_task parameter is added ).

The other three modes can coexist with other activities.

 

4. Whether to generate a new instance every time

"Standard" generates a new activity instance for none of the intent instances that start the activity;

If the activity of "singletop" is at the top of the stack of the task, no new instance of the activity will be generated, and the instance at the top of the stack will be directly used. Otherwise, the instance of the activity will be generated.

For example, now the task stack element is A-B-C-D (D at the top of the stack), this time to d to start intent, if D is "standard", then generate a new instance of D, stack to a-B-c-d.

If D is singletop, no new instance of D will be produced and the stack status remains A-B-C-D

If intent is sent to B at this time, a new instance of B will be generated no matter whether the launchmode of B is "standard" or "singletop, stack status changes to a-B-c-d-B.

 

"Singleinstance" is the only activity in the stack where it is located. It will be reused every time.

 

If "singletask" is on the top of the stack, intent is accepted. Otherwise, the intent will be discarded, but the task will still return to the foreground.

 

When an existing activity instance processes a new intent, the onnewintent () method is called.

If you receive an intent to generate an activity instance, you can use the back key to return to the previous state. If an existing activity is used to process this intent, you cannot press the back key to return the previous status.

 

 

 

This article is from the Internet. The source address has been forgotten. The original author can contact me to indicate the copyright!

 

Summary:

Standard is created every time, and each task can have multiple instances (each task can have multiple instances)
If the current singletop instance is at the top of the stack, the onnewintent of the instance will not be created. If it is not at the top of the stack, a new instance is created (each task can have multiple instances and can be reused at the top of the stack)
Singletask creates a new task. If another task already exists and contains the instance, the instance of the task is called directly. (Only one task exists)
Singleinstance creates a new task and has only one unique instance in the task. (Only one task exists, and only one task exists)

Flag_activity_new_task is similar to singletask.
Flag_activity_single_top is similar to singletop
Flag_activity_clear_top does not match

With two diagrams, I think it is clear:

(1) Standard

(2) singletask

TASKA taskb can be understood as two applications. For example, TASKA is your current application and taskb is the default browser.

When task KB is entered, press the return key. You must first return to the root in task kb before returning to task ka.

Summarize the following statements:

Standard is created every time, and each task can have multiple instances (each task can have multiple instances) if the current singletop instance is at the top of the stack, the onnewintent of the instance will not be created. If it is not at the top of the stack, a new instance is created (each task can have multiple instances and can be reused at the top of the stack). singletask creates a new task, if another task already exists and contains the instance, the instance of the task is called directly. (Only one task exists) singleinstance creates a new task and has only one unique instance in the task. (Only one task exists, and only one task exists)

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.