AndroidManifest. xml file (activity) (3)

Source: Internet
Author: User

Android: launchMode

This attribute defines a command to start the Activity. There are four working modes that will be combined with the Activity tag (FLAG_ACTIVITY _ * constant) in the Intent object to determine what should happen when the called Activity processes the Intent object, the four modes are:

Standard

SingleTop

SingleTask

SingleInstance

The default mode is standard.

As shown in the following table, these four modes are divided into two groups: standard and singleTop, and singleTask and singleInstance. Activity with standard and singleTop startup modes can be instantiated multiple times. Its instances can belong to any task and can be defined in the stack of the Activity. Generally, the startActivity () method is called to load them into the task (unless the Intent object contains a FLAG_ACTIVITY_NEW_TASK command, a new task will be started in this case .)

In contrast, the singleTask and singleInstance startup modes can only start one task. They are always the root nodes of the Activity stack. And the device can only have one such Activity at a time-only one such task.

The standard and singleTop modes are different in one aspect: for an Activity in standard startup mode, each time a new Intent object is required to start, the system will create a new Activity class instance to respond to the Intent Object Request. Each instance processes an Intent object. Similarly, the Activity in singleTop Startup Mode creates a new instance to process a new Intent object. However, if the target task has an instance of this Activity at the top of the stack, the instance will accept this new Intent object (called in the onNewIntent () callback method ); instead of creating a new Activity instance. In another case, for example, if an instance of the singleTop startup Activity already exists in the target task, but it is not at the top of the task stack or at the top of the stack, instead of a target task, a new Activity instance is created and pushed to the target Task Stack.

The singleTask and singleInstance modes are also different in one aspect: the singleTask mode Activity allows other activities to be part of its task. It is always in the root node of the task, but other activities (which must be standard and singleTop modes) can be loaded into the task. In singleInstance mode, other activities are not allowed to be part of the task. It is the only Activity in the task. If you want to start another Activity, the started Activity must be associated with different tasks, just as if the FLAG_ACTIVITY_NEW_TASK tag is set in the Intent object.

Use Cases Startup Mode Does it support multiple instances? Explanation
Startup modes for most activities Standard Yes By default, the system creates a new Activity instance in the target task and sends the Intent object to it.
SingleTop Conditional If the Activity in this mode always exists at the top of the stack of the target task, the system will send the Intent object to this instance by calling its onNewIntent () method, instead of creating an Activity instance.
Special startup modes are not recommended. SingleTask No The system creates the Activity at the root node of a new job stack and sends the Intent object to it. However, if the instance of this Activity already exists, the system will send the Intent object to this instance by calling its onNewIntent () method, instead of creating an Activity instance.
SingleInstance No Except that the system cannot load other activities to the tasks to which the Activity instance belongs, the other activities are in the same singleTask mode. In this mode, the Activity always exists independently and is the only member of the task.
As shown in the table above, the standard mode is the default mode and applies to most activities. SingleTop is also a common startup mode used by many Activity types. Other modes (singleTask and singleInstance) are not recommended to most applications because they generate unfamiliar interaction modes and are different from most applications.
Regardless of the Startup Mode selected, you must test the availability of the Activity during startup and be able to return other activities and tasks when you use the Back button.
 



From FireOfStar's column

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.