Details about Android Startup Mode

Source: Internet
Author: User

When Android has been switched to the Android startup mode, when an existing activity processes a new intent, the user cannot press the BACK key, which is the result of some self-summary, thank you for your reference.

The Android Startup Mode of different programs can share an affinity; the activity of the same program can use different afninity. Afninity is enabled when the following two conditions are met: When the Intent that starts acitity contains the FLAG_ACTIVITY_NEW_TASK node, or the allowTaskReparenting attribute of an activity is set to "true ".

As mentioned earlier, the default activity activated by the task through startActivity () is also in the same stack as other activities. However, the Intent that triggers this activity passes the FLAG_ACTIVITY_NEW_TASK node through the startActivity () method. This node indicates a new task. However, not necessarily; if the task does not contain the activity of this afinity, it starts from the default activity.

If the allowTaskReparenting attribute of the activity is set to "true", the allowTaskReparenting node can exit its task and go to the next task through its afinity guidance. For example, assume that "Tourism software" has an activity that can obtain the weather conditions of a specified city.

This activity and other activities in this program have the same afinity default afinity ). You are allowed to re-transfer to another task. An activity starts the weather forecast. It first belongs to this task. However, when the travel program runs on the foreground, the weather forecast acivity is assigned to the tourism program to run the program.

If a .apk file contains many programs, you must assign a different affinity to activitis as appropriate. Which task will contain the activity specified by intent: For standard and singleTop modes, the intent that starts the activity.

(Call startActivity () method)-unless the intent object contains the FLAG_ACTIVITY_NEW_TASK node, if yes, it will be as described in the previous chapter, Affinities and new tasks, another task will carry this activity.

Relatively, the "singleTask" and "singleInstance" modes make the activity always at the root of tast. They initialize a task and will not integrate it into other tasks. Whether the activity has multiple instances. "standard" or "singleTop" modes can be used as examples for multiple times. The activity belongs to multiple tasks or has multiple instances in one task.

In comparison, the activities of the "singleTask" and "singleInstance" modes are limited to only one instance. Because these activities are at the root of the task, this indicates that there is only one task. Whether there can be other activities in the same task: "singleInstance" mode, the activity in the task cannot have other activities, if other activities are started.

Other activities will be appended to the new task no matter what the Android Startup Mode of the new activity is)-Just like intent uses the FLAG_ACTIVITY_NEW_TASK tag. In other respects, there is no difference between "singleInstance" and "singleTask.

The other three modes allow multiple acitvity in the same task. The activity of singleTask must be at the root of the task. It can start other activities set to this task. Standard and singleTop can be used anywhere in a task.

Whether the new instance of a class can accept or process intent sent from other parts: the default "standard" mode can respond to any new intent. Each instance processes an intent. If the activity in "singleTop" mode is at the top of the task, an existing instance is used to process the intent of all requests to the instance. Otherwise, a new instance is created and pushed to the top of the task.

For example, a job contains the root activityA, and other activityB, C, D, D at the top of the job stack, that is, the stack is a A-B-C-D. An intent request D. If D is in "standard" Android boot mode, a new instance of D is created, and the job stack changes to A-B-C-D-D..

If D's Android Boot Mode is "singleTop", then the existing D instance responds to intent, so the job stack is still A-B-C-D. in another case, if intent requests B, if B is in "standard" or "singleTop" mode, B creates a new instance to respond, the task stack is A-B-C-D-B.

As mentioned above, the activity of "singleTask" or "singleInstance" has only one instance, so this instance must process all intents. The "singleInstance" activity is always at the top of the task stack because it is the only activity in the task), so this instance processes all intent. Other activities may be at the top of the "singleTask" activity, so this instance will not process intent requests, so intent requests will fail; even if it fails, intent will activate this program)

Note: When an instance of a new activity is created in response to the intent, you can press the BACK key to return to the previous activity ). However, when an existing activity processes a new intent, you cannot press the BACK key.

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.