Android经典完美退出办法,运用单例形式创立一个Activity办理目标,该目标中有一个Activity容器(详细完成自己处理,运用LinkedList等)专门担任存储新敞开的每一个Activity,而且简单了解、易于操作,十分不错!
AppUtils类(贮存每一个Activity,并完成封闭一切Activity的操作)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cpic.jscx.android.utils;
import android.app.Activity;
import android.app.Application;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author user
*/
public class AppUtils extends Application{
private List activityList = new LinkedList();
private static AppUtils instance;
private AppUtils()
{
}
//单例形式中获取仅有的app实例
public static AppUtils getInstance()
{
if(null == instance)
{
instance = new AppUtils();
}
return instance;
}
//增加Activity到容器中
public void addActivity(Activity activity)
{
activityList.add(activity);
}
//遍历一切Activity并finish
public void exit()
{
for(Activity activity:activityList)
{
activity.finish();
}
System.exit(0);
}
}