Android only activity four boot mode

Source: Internet
Author: User

There are four ways to activate the Activity, namely:

Standard
Singletop
Singletask
SingleInstance

You can set up a corresponding startup mode for your activity according to your actual needs , so you can avoid creating a large number of repetitive activity issues.

To set the Activity 's startup mode, only the corresponding <activity> in the Androidmanifest.xml Label Settings android:launchmode Properties

Here are the four modes of action:

Standard default mode, which can be configured without writing. In this mode, a new instance will be created by default. Therefore, in this mode, you can have multiple identical instances, and also allow multiple identicalActivityoverlay.

For example:
If I had aActivityname isA1,There is a button to jump toA1. So if I click on the button, I'll start a new one.Activity A1stacked in just theA1above, and then click on it, and then City one above it...
Point BackThe keys are exited sequentially in the order of the stacks.

Singletop can have more than one instance, but it does not allow multiple identicalActivityoverlay. That is, ifActivityat the top of the stack, start the sameActivity, the new instance is not created and itsonnewintentmethod.

For example:
If I had twoActivityname isB1,b2,two xActivityThe content function is exactly the same, there are two buttons to jump toB1orB2, the only difference isB1to be Standard,B2to beSingletop.
If the order I intend to open isb1->b2->b2, the order in which they are actually opened isb1->b2(last attempt to openB2, only the previous one was actually calledonnewintentmethod)
If the order I intend to open isb1->b2->b1->b2, the order in which it is actually opened is consistent with the intent,b1->b2->b1->b2.
Singletask has only one instance. When launching him in the same application, ifActivitydoes not exist, it will be in the currentTaskcreates a new instance that, if present, willTaskThe other on top of itActivity destorydrop and call it.onnewintentmethod.
If you start it in another application, a newTask, and in thatTaskstart this inActivity,SingletaskAllow otherActivityrather than in aTaskThe CCP exists, that is to say, if I were in thisSingletaskinstance, and then open the newActivity, this newActivitywill still be inSingletaskthe instance ofTaskthe.

For example:
If there are three of my applicationsACTIVITY,C1,C2,C3, three xActivitycan start each other, whereC2to beSingletaskmode, then, regardless of how I click Start in this program, such as:C1->C2->C3->C2->C3->C1-C2,C1,C3There may be multiple instances, butC2there will only be one, and these threeActivityare all in the sameTaskinside.
ButC1->C2->C3->C2->C3->C1-C2, such a procedure should actually be the following, becauseSingletaskwill putTaskThe other on top of itActivity destoryoff.
Operation:c1->c2 c1->c2->c3 c1->c2->c3->c2 c1->c2->c3->c2->c3->c1 C1->C2->C3->C2->C3->C1-C2
Actual:c1->c2 c1->c2->c3 c1->c2 c1->c2->c3->c1 C1->C2

If another application opensC2, you will start a newTask.
such as other applications Otherhas aActivity,taskIdto be $, open from itC2, youC2of theTaskidiNot for $, such asC2of thetaskIdto be201, then fromC2OpenC1,C3, youC2,C3of thetaskIdis still201.
Note: If at this point you clickHome, and then open Otherand found that it would certainly be OtherThe content in the app, not the one in our appC1 C2 C3One of the two.
SingleInstance has only one instance, and this instance runs independently in aTask, thisTaskonly this instance, not allowed to have otherActivityexist.

For example:
There are three of programsactivityd1,d2,d3, three xActivitycan start each other, whereD2to besingleinstancemode. Then the program fromD1start running, assumingD1of thetaskIdto be $, then fromD1StartD2when theD2will start a newTask, i.e.D2with theD1not aTaskrun in. AssumptionsD2of thetaskIdto be201, and then fromD2StartD3when theD3of thetaskIdto be $, which means it's being pressed to theD1start the task stack.

If you open it in another applicationD2, assuming Otherof thetaskIdto be $, openD2,D2will create a newTaskrun, assuming it'staskIdto be201, then, if then fromD2StartD1orD3, you will create anotherTask, therefore, if the operation steps areother->d2->d1, the process involves3aTaskup.


Android only activity four boot mode

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.