用一个集合类对所有的Activity进行管理,实现随时控制Activity。用add(Activity activity)方法向List中添加Activity,用remove(Activity activity)方法从List中移除Activity,用finishProgram()方法将List中所有Activity移除并退出程序
import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.util.Log; public class ActivityStackControlUtil { private static List<Activity> activityList = new ArrayList<Activity>(); public static void remove(Activity activity) { activityList.remove(activity); } public static void add(Activity activity) { activityList.add(activity); } public static void finishProgram() { Log.i("oyp", "finishProgram"); for (Activity activity : activityList) { if (!activity.isFinishing()) { activity.finish(); } } android.os.Process.killProcess(android.os.Process.myPid()); } }
====================================================================================
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
====================================================================================