Android 4 Boot Mode

Source: Internet
Author: User

In Android, there are 4 activation modes for the activity, namely:

"Standard" (default)

"Singletop"

"Singletask"

"SingleInstance"

They are mainly different from the following:

1. How to decide which task to belong to

The target TASK for the ACTIVITY of "standard" and "Singletop", and the sender of the received intent within the same task, unless intent includes the parameter flag_activity_new_task.

If the Flag_activity_new_task parameter is supplied, it is launched into another task.

"Singletask" and "singleinstance" always use activity as the root element of a task, and they will not be launched into one other task.

This remark is not correct, thank liuluxu1989.

This blog post is relatively simple, there is no diagram, inconvenient for everyone to understand, set up a direct look at 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, and a task can include multiple instances of an activity;

"Singletask" and "singleinstance" restrict the generation of only one instance, and are the root elements of a task.

Singletop requires that if the stack top already has an instance of the activity to create when the intent is created, the intent is sent to the instance without sending it to the new instance.

3. Allow other activity to exist within this task

"SingleInstance" exclusive of a task, other activity cannot exist in that task; if it launches a new activity, regardless of the new activity's launch mode, The new ACTIVITY will be run in another task (as with the Flag_activity_new_task parameter).

The other three modes can coexist with other activity.

4. Whether to generate a new instance every time

"Standard" for not a start intent will generate a new instance of activity;

The activity of "singletop" if it is at the top of a task's stack, does not generate a new instance of the activity, directly using the instance at the top of the stack, otherwise, generates an instance of the activity.

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

If D is singletop, a new instance of D will not be produced, and the stack state is still a-b-c-d

If at this time to B hair intent, whether B launchmode is "standard" or "singletop", will generate a new instance of B, the stack status becomes A-b-c-d-b.

"SingleInstance" is the only activity on its stack, which is reused every time.

"Singletask" if at the top of the stack, accept intent, otherwise the intent will be discarded, but the task will still return to the foreground.

The Onnewintent () method is called when the existing activity instance processes the new intent

If you receive intent to generate an activity instance, the user can return to the previous state via the back key, and if an activity already exists to handle the intent, the user cannot return to the previous state by pressing the back key.

The article from the network, the source address has been forgotten, the original author can contact me to indicate the copyright!

Summarize:

Standard is new each time, each task can have, and each task can have multiple instances (each task can have, and can have more than one)
Singletop If the current instance is at the top of the stack, the instance is not created and its onnewintent is called. If not at the top of the stack, create a new instance (each task can have and can have multiple, reusable at the top of the stack)
Singletask creates a new task, and if there is already another task and contains the instance, call the instance of that task directly. (Only one task will be available)
SingleInstance creates a new task, and only one instance of it is in the task. (Only one task will have it, and it is only in that task)


Flag_activity_new_task similar to Singletask
Flag_activity_single_top similar to Singletop
Flag_activity_clear_top No correspondence

With two pictures, I think it's clear:

(1) Standard

(2) Singletask

Taska TASKB can be understood as two applications, such as Taska is your current application, TASKB is the default browser.

When you are in TASKB, press the back key to return to root in TASKB before returning to Taska.

Sum it up into the following sentences

[Plain]View Plaincopyprint?
      1. Standard is new each time, each task can have, and each task can have multiple instances (each task can have, and can have more than one)
      2. Singletop If the current instance is at the top of the stack, the instance is not created and its onnewintent is called. If not at the top of the stack, create a new instance (each task can have and can have multiple, reusable at the top of the stack)
      3. Singletask creates a new task, and if there is already another task and contains the instance, call the instance of that task directly. (Only one task will be available)
      4. SingleInstance creates a new task, and only one instance of it is in the task. (Only one task will have it, and it is only in that task)

Android 4 Boot Mode

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.