public class ExitApplication extends Application { private static ExitApplication instance ; List<Activity> activityList = new ArrayList<Activity>() ; private ExitApplication(){} public static ExitApplication getInstance(){ if(instance==null){ instance = new ExitApplication() ; } return instance ; } public void addActivity(Activity activity){ activityList.add(activity) ; } public void exit(){ for(Activity activity:activityList){ activity.finish() ; } System.exit(0) ; } }
先新建一个这个类。
然后在需要finish的activity里的onCreate()方法内添加
ExitApplication.getInstance().addActivity(this);
最后再在你要结束程序的地方添加
ExitApplication.getInstance().exit();
还有 。在manifest 里边注册 也挺重要的 不然没用
<application android:name="包名.ExitApplication"