Androge-activity Four startup modes

Source: Internet
Author: User

In the process of developing a project, we involve jumps between multiple activity components in the application, or the reusable activity of other applications. For example, we might want to jump to a previous activity instance instead of generating a lot of repetitive activity. This requires that we configure a specific load pattern for the Activity, rather than using the default load mode.

set the location of the activity element's Android:launchmode property in the Androidmanifest.xml file: <activity android:name= "ACTB" Android:launchmode = "Singletask" ></activity>


Activity has four modes of loading

[1] Standard mode

      This is the default mode, and the activity instance is created each time the activity is activated and placed in the task stack. Therefore, in this mode, you can have multiple identical instances, and also allow multiple identical activity overlays.

For example:
If I have an activity named A1, there's a button to jump to A1. Then if I click on the button, it will start a new activity A1 stacked on the A1 just above, then click on it, and then City one on it ...


[2] Singletop mode

If there is an instance of the activity at the top of the task, the instance is reused (Onnewintent () of the instance is invoked), otherwise a new instance is created and placed on top of the stack, even if an instance of the activity already exists in the stack, and a new instance is created as long as it is not at the top of the stack.

If I have two activity named B1,B2, two activity content function is identical, there are two buttons can jump to B1 or B2, the only difference is B1 standard,b2 for Singletop.
if the order in which I intend to open is b1->b2->b2, then the actual order of opening is B1->B2 (the next attempt to open B2, which actually calls only the previous Onnewintent method)
if the order in which I intend to open is b1->b2->b1->b2, then the actual order of opening is the same as the intention, b1->b2->b1->b2.

[3] Singletask mode

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 moved out of the stack. If the instance does not exist in the stack, a new instance is created to be put into the stack.

There is only one instance. When you launch him in the same application, if the activity does not exist, a new instance is created in the current task and, if present, the other activity on top of the task is destory off and the Onnewintent method is called.
If you start it in another application, a new task is created and started in that task Activity,singletask allows other activity to be stored in a task, that is, If I open a new activity in this Singletask instance, the new activity will still be in the task of the Singletask instance.

[4] singleinstance mode

Create an instance of the activity in a new stack and have multiple apps share that activity instance in the stack. Once the activity instance of the pattern already exists in a stack, any application that activates the activity will reuse the instance in that stack (the onnewintent () of the instance is invoked). The effect is that multiple apps share an app, regardless of who activates the Activity into the same app.

There is only one instance, and this instance runs independently in a task, and this task is the only instance that does not allow any other activity to exist.

when the patternActivityinstance is created in the task stack, as long as the instance is still in the task stack, that is, if the type is activatedActivity, it will be called by invoking the instance'snewinstance ()method to reuse theActivity, the same one is used at this timeActivity Instances, it will be at the top of the stack on the task stack. This mode is typically used to load slower, less expensive performance and do not need to re-create each timeActivity.

"Take doctrine" standard mode. Where to call me I'll go where, can be instantiated multiple times, can be several of the same activity overlap.

"Deny stacking" singletop mode. It can be instantiated multiple times, but not multiple identical activity overlaps, and the onnewintent function is called when the top of the stack is the same activity.

"Lonely Lonely" singleinstance mode. When the activity is loaded, if it is not instantiated, he creates a new task, instantiates it into the stack, and if it already exists, calls Onnewintent directly, and the activity's task does not allow other activity to start. Any other activity initiated from the activity will be placed in another task, first checking if there is a task for the application, and creating it without it.




Androge-activity Four startup modes

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.