Four modes of loading for activity

Source: Internet
Author: User

In Android, there are 4 activation modes for the activity: standard, Singletop, Singletask and SingleInstance, where standard and singletop are similar, Singletask and singleinstance are similar, use the following:

(1). Standard and Singletop

In both load modes, multiple instances of an activity can exist in the same task, and can be anywhere in the activity stack.

Let me give you an example:

Assume that the activity stack for the target task is: a->b->c->d (stack bottom, top of stack)

Calling StartActivity (D) in the program

If D is standard mode, the activity stack changes to:

A->b->c->d->d, which will re-create a D instance

if D is singletop mode, the activity Stack becomes :

A->b->c->d, the D instance is not created, that is, if D is at the top of the activity stack of the target task, it does not create a new instance, but rather calls the Onnewintent () method of D, and vice versa if D is not in the target task The top of the activity stack, a D instance is recreated

(2). Singletask and SingleInstance

In both load modes, only one instance of the activity exists in the same task, and if started by StartActivity (), the Onnewintent () method is called instead of creating a new instance. In both of these modes, activity instances are located at the bottom of the activity stack.

The difference between the two load modes:

Suppose an activity instance a uses the following two loading modes:

Singletask:

If a calls StartActivity (b) to start the B instance, a and B are in the same task.

SingleInstance:

If a calls StartActivity (b) to start a B instance, the system automatically adds a property flag_activity_new_task to intent, puts the B instance into a new task, which means that the a instance is in a task that has only a self, No other instances exist

Four modes of loading for activity

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.