Android Development Exit Interface

Source: Internet
Author: User

The first step:

Define a Exitapplication class that inherits from application, creating a method for collecting and managing activity, collecting the activity in a collection, and creating a method for emptying and closing the activity;

Package com.fishing.exit;

Import java.util.ArrayList;
Import java.util.List;

Import android.app.Activity;
Import android.app.Application;
Import Android.content.Context;

public class Exitapplication extends application {


/*
* Manage and collect activity tools
*
* */

Private list<activity> List = new arraylist<activity> ();//Add Activity Object

private static exitapplication application;

Private Exitapplication () {

}

public static Exitapplication getinstance () {
if (null = = Application) {
application = new Exitapplication ();
}
return application;
}

/*
* Manage activity and add interfaces that need to be managed
* */
public void addactivity (activity activity) {
List.add (activity);
}

/*
* Clear activity, close the interface
* */
public void exit (context context) {
for (Activity activity:list) {
if (activity!=null) {
Activity.finish ();
}

}
System.exit (0);
}

}

Step Two:

In each activity's OnCreate method, add

Exitapplication.getinstance (). addactivity (this);//activity Management stack

Step Three:

Called in the place where you want to exit

Exitapplication.getinstance (). exit;

Android Development Exit Interface

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.