参考1:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=160357
这里说退出有两钟:单列和广播。记得要配置Application
package com.nassware.android.rchhealth.util;
import java.util.LinkedList;
import android.app.Activity;
import android.app.Application;
/**
* 单列模式来实现完全退出
* @author
*
*/
public class MyApplication extends Application {
private LinkedList<Activity> activityList = new LinkedList<Activity>();
private static MyApplication instance;
private MyApplication()
{
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
this.instance = this;
}
//单例模式中获取唯一的MyApplication实例
public synchronized static MyApplication getInstance()
{
if(null == instance)
{
instance = new MyApplication();
}
return instance;
}
//添加Activity到容器中
public void addActivity(Activity activity)
{
activityList.add(activity);
}
//遍历所有Activity并finish
public void exit()
{
try {
for (Activity activity : activityList) {
if (activity != null)
activity.finish();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.exit(0);
}
}
@Override
public void onLowMemory() {
// TODO Auto-generated method stub
super.onLowMemory();
System.gc();
}
}
http://blog.csdn.net/fxtxz2/article/details/7571943