Activity startup mode in Android

Source: Internet
Author: User

Every interface in Android is an activity, and switching interface operations is actually an instantiation of multiple different activity. The startup mode of activity in Android determines how the activity starts running.

Activity startup mode settings:

<activity android:name= ". Mainactivity "android:launchmode=" standard "/>

The activation mode of activity is divided into four types:

1. Standard

In standard mode (that is, default mode), no configuration of Launchmode is required, and activity is created each time the activity is activated and placed in the task stack.

2. Singletop

If there is an instance of the activity at the top of the task, reusing the instance will create a new instance and put it in the top of the stack (even if the activity instance already exists on the stack, as long as it is not on top of the stack, an instance will be created).

3. Singletask

If an instance of the activity is already in the stack, the instance is reused (Onnewintent () of the instance is invoked). When reused, the instance is returned to the top of the stack, so instances above it will be removed from the stack (note: After removal, the system will be destroyed). If the instance does not exist in the stack, a new instance is created to be put into the stack.

4. SingleInstance

Create the activity instance in a new stack and have multiple apps share the activity instance in the stack. Once an instance of the activity in the schema is present on a stack, any application that activates the activity will reuse the instance in that stack, with the effect of sharing an app with multiple applications, regardless of who activates the activity into the same application.

This startup mode works similarly to the browsers we use, and we all know that when accessing a browser in multiple programs, if the current browser is not open, the browser opens, otherwise it will be accessed in the currently open browser. This mode saves a lot of system resources because he can guarantee that the activity object to be requested only exists in the current stack.

Activity4 type of startup mode comparison table

The
difference Allow multiple instances How to determine the owning Whether the task generates a new instance each time allows other activity to exist within this task
standard can be instantiated multiple times, the same Different instances of a task can be in different tasks, and each task can contain more than one instance of that is stored at the start Activity ()
Task. Unless you set the
flag_activity
_new_task tag
yes allow
singletop Same as Standa Rd same as standard if the activity is hosted at the top of the activity, it is processed directly with the activity; otherwise, a new instance is created allow
Singletaskcannot have more than one instance. Since the activity is always at the top of the stack in this mode, there is at most one instance of actvity in the same device placed in a new task, and the root of the task only creates a new instance the first time. Other cases are reused by the activity to allow. If the stack that holds the Singletask is hosted in a task and responds to a intent, if Singletask is at the top of the stack, the intent is processed, or intent is lost, but the task is in the foreground
SingleInstance with Singletask with Singletask with Singletask not allowed

Reference URL:

http://blog.csdn.net/wotoumingzxy/article/details/8279731

Activity startup mode in Android

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.