原理:用链表存储activity页面,然后当你退出的时候就按退出,把链表里面所有activity都关闭掉
package com.by2n.application;
import java.util.LinkedList;
import java.util.List;
import android.app.Activity;
public class Application extends android.app.Application {
@Override
public void onLowMemory() {
// TODO Auto-generated method stub
super.onLowMemory();
System.gc();
}
private List<Activity> mList = new LinkedList<Activity>();
private static Application instance;
public synchronized static Application getInstance(){
if(null == instance){
instance = new Application();
}
return instance;
}
public void addActivity(Activity activity){
mList.add(activity);
}
public void exit(){
try{
for(Activity a:mList){
if(a != null){
a.finish();
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
System.exit(0);
}
}
}