标签:android style blog http color java io strong for
一、将统一管理Activity的类ActivityManager复制到工程里面。
package com.jsmtr.www.Helper;
import java.util.LinkedList;
import java.util.List;
import android.app.Activity;
import android.app.Application;
public class ActivityManager extends Application {
@SuppressWarnings("rawtypes")
private List list = new LinkedList();
private static ActivityManager instance;
private ActivityManager () {
}
public synchronized static ActivityManager getInstance() {
if (null == instance) {
instance = new ActivityManager ();
}
return instance;
}
@SuppressWarnings("unchecked")
public void addActivity(Activity activity) {
list.add(activity);
}
public void exit() {
try {
for (int i = 0; i < list.size(); i++) {
Activity activity = (Activity) list.get(i);
if (activity != null)
activity.finish();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.exit(0);
}
}
public void onLowMemory() {
super.onLowMemory();
System.gc();
}
}
二、在每个Acitivity的oncreate方法里面添加当前Acitivity到ancivitylist里面去。
ActivityManager.getInstance().addActivity(this);
三、想退出系统的时候直接调用ActivityManager中的退出方法即可。
ActivityManager.getInstance().exit();
推荐博文:Android实现点击两次返回键退出
标签:android style blog http color java io strong for
原文地址:http://www.cnblogs.com/myfaith/p/3935901.html