«

Android 退出整个应用程序

时间:2024-3-2 17:20     作者:韩俊     分类: Android


“三步走”

1、建立一个JAVA类

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.Application;


public class SysApplication extends Application {

private List<Activity> mList = new LinkedList<Activity>();
private static SysApplication instance;

private SysApplication() {
}

public synchronized static SysApplication getInstance() {
if (null == instance) {
instance = new SysApplication();
}
return instance;
}

public void addActivity(Activity activity) {
mList.add(activity);
}

public void exit() {
try {
for (Activity activity : mList) {
if (activity != null)
activity.finish();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.exit(0);
}
}

public void onLowMemory() {
super.onLowMemory();
System.gc();
}

}
2、在每个界面onCreate()方法中添加此行
SysApplication.getInstance().addActivity(this);

3、退出菜单调用exit()方法

标签: android

热门推荐