Android Development completely quits activity

Source: Internet
Author: User

We exit the activity can be called: Finish (), System (0), but these are simply quitting a single activity


Some people will say that directly kill the process, these practices are not very desirable, in fact, we look at the API can be found that the Activity


Are all put into the stack management, we just have to empty the stack, not completely out of it. To the stack of activity


Management, you need to understand the four states of Launchmode, here is not much to say, look at the API.


We use android:launchmode= "Singletop", when the activity is on top of the stack, it empties the activity underneath it.


Then finish off the current activity and close it completely.




Instance a,b,c,d four Activity;a as a portal, set android:launchmode= "Singletop" in Manifest.xml


Several others do not need to be set. Boot order A->b->c->d


Here we add the flag intent.flag_activity_clear_top in intent when we open the A window in the D window.


When you turn on a again, all activity for that process space will be cleared.


Use the following code in D:
Intent Intent = new Intent ();
Intent.setclass (D.this, A.class);
Intent.setflags (Intent.flag_activity_clear_top); Note the flag setting of the bank
StartActivity (Intent)
Finish ();

A In the code:
protected void Onnewintent (Intent Intent) {super.onnewintent (Intent);//Exit if (Intent.flag_activity_clear_top & Intent.getflags ())! = 0) {finish ();}}




Because A is android:launchmode= "singletop" does not call OnCreate (), but responds Onnewintent ()


At this time Judge Intent.flag_activity_clear_top, then put a finish () off.


B,c was also cleared, because A is android:launchmode= "Singletop", and the stacks below are cleared.


All a,b,c,d in the stack are cleaned up. So the whole program exited.

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.