Learn from Android-how to turn off all activity

Source: Internet
Author: User

According to the activity's declaration cycle
Method 1
We know that the Android window class provides a history stack, which we can skillfully implement using the stack principle, where we add the flag intent.flag_activity_clear_top directly to the Intent when opening the b window in a window. When you turn on B, all activity for that process space will be cleared.

In the a window, use the following code to invoke the b window
Java code

Intent Intent = new Intent ();
Intent.setclass (Android123.this, Cwj.class);
Intent.setflags (Intent.flag_activity_clear_top); Note the flag setting of the bank
StartActivity (Intent)

Method 2:

In the call exit method, write the

Myapplication.getinstance (). exit ();

public class MyApplication extends application {

Private list<activity> activitylist = new linkedlist<activity> ();
private static MyApplication instance;

Private MyApplication () {
}

Get a unique MyApplication instance in singleton mode
public static MyApplication getinstance () {
if (null = = Instance) {
Instance = new MyApplication ();
}
return instance;

}

Adding activity to the container
public void addactivity (activity activity) {
Activitylist.add (activity);
}

Traverse all activity and finish
/*
* Add the activity to the MyApplication object instance container in each activity's OnCreate method
*
* Myapplication.getinstance (). addactivity (this);
*
* Call the Exit method when you need to end all activity
*
* Myapplication.getinstance (). exit ();
*/
public void exit () {

for (Activity activity:activitylist) {
Activity.finish ();
}

System.exit (0);

}

Learn from Android-how to turn off all 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.