Introduction to the 4 startup modes of "Android" activity

Source: Internet
Author: User

First of all, we must know that activity is managed in a stack (LIFO) structure.

When activity a starts activity B, a is pressed into the stack, and B is at the top level of the stack. When B calls finish () to end the activity, B pops up from the stack, at which point A is at the top level of the stack.

We can implement the change of the startup mode by specifying the android:launchmode= "standard" property in the Activity node of the Androidmanifest.xml file.

Well, to understand how the activity is managed, let's get to know the 4 startup modes of the activity.

1:stand

This standard boot mode is used if you do not specify a startup mode. For example, if we start activity A, the a,a will be re-created and pressed into the stack, regardless of whether the stack is already present.

2:singletop

The top level activity is unique. For example, if we start activity A, if a is already present at the top of the stack, then use a directly.

3:singletask

The only activity in the stack. and 2 The biggest difference is that this mode regardless of where you live on the stack, as long as the start a is found in the stack, the activity on A is all destroyed (life cycle such as ondestory will also be executed), directly using a

4:singleinstance

Create a new stack to manage this activity.

For example, we specify the active B boot mode to SingleInstance, a, c default to use stand, and a, B, C, to start three activities:

C Activity Finish (), the return is a (instead of B, because the stack of management B is independent of AC); a activity finish (), then the current stack is empty, and then found the other stack (that is, the stack where activity B resides).

Introduction to the 4 startup modes of "Android" activity

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.