public class ScreenManager {private static Stack activityStack;private static ScreenManager instance;private ScreenManager() {}public static ScreenManager getScreenManager() {if (instance == null) {instance = new ScreenManager();}return instance;}public void popActivity() {Activity activity = activityStack.lastElement();if (activity != null) {activity.finish();activity = null;}}public void popActivity(Activity activity) {if (activity != null) {activity.finish();activityStack.remove(activity);activity = null;}}public Activity currentActivity() {Activity activity = activityStack.lastElement();return activity;}public void pushActivity(Activity activity) {if (activityStack == null) {activityStack = new Stack();}activityStack.add(activity);}//除了当前activity,其他activity全被清除出栈public void popAllActivityExceptOne(Class <?>cls) {while (true) {Activity activity = currentActivity();if (activity == null) {break;}if (activity.getClass().equals(cls)) {break;}popActivity(activity);}}}
activity栈管理类ScreenManager
最新推荐文章于 2024-07-23 10:40:12 发布