private static App app; //维护所有Activity的集合 private static List<Activity> activities; private static AppCompatActivity mCurrentAc;//当前界面的
public static Application getInstance() { synchronized (App.class) { return app; } } //维护一个新的Actiivty public static void addActivity(Activity ac) { if (null == activities) { activities = new ArrayList<>(); } activities.add(ac); } //移除一个Activity public static void removeActivity(Activity ac) { activities.remove(ac); } //清除所有Activity public static void clearAll() { for (Activity ac : activities) { if (!ac.isFinishing()) { ac.finish(); } } } //保存当前所在的activity public static void setCurrentAc(AppCompatActivity ac) { mCurrentAc = ac; } //获取当前所在的activity public static AppCompatActivity getCurrentAc() { return mCurrentAc; }