代码
public class KillProcess { private static KillProcess killProcess = null; private List<Activity> activityList = new ArrayList<>( ); private KillProcess(){ } public static KillProcess getInstance(){ if (killProcess == null){ Sync(); } return killProcess; } private static synchronized void Sync(){ if (killProcess == null){ killProcess = new KillProcess(); } } public void addActivity(Activity activity) { activityList.add(activity); } public void finishAll() { for (Activity activity : activityList) { if (!activity.isFinishing()) { activity.finish(); } } } }
引用
获取实例
killProcess = KillProcess.getInstance();
添加Activity
在每一个Activity下添加如下代码
killProcess.addActivity( AddClockActivity.this );
杀死所有Activity
killProcess.finishAll();