• AppManager


    1.统一应用程序中所有的Activity的栈管理
      涉及到activity的添加、删除指定、删除当前、删除所有、返回栈大小的方法

    public class AppManager {
    
        private Stack<Activity> activityStack = new Stack<>();
    
        //设置当前类是单例的
        private static AppManager appManager = new AppManager();
        private AppManager(){}
        public static AppManager getInstance(){
            return appManager;
        }
    
        public void addActivity(Activity activity){
            activityStack.add(activity);
        }
    
        public void removeActivity(Activity activity){
            for(int i = activityStack.size() - 1; i >= 0 ; i--) {
                if(activityStack.get(i).getClass().equals(activity.getClass())){
                    activity.finish();
                    activityStack.remove(i);
                    break;
                }
            }
        }
    
        public void removeCurrent(){
    //        Activity activity = activityStack.get(activityStack.size() - 1);
            Activity activity = activityStack.lastElement();
            activity.finish();
            activityStack.remove(activity);
        }
    
        public void removeAll(){
            for(int i = activityStack.size() - 1; i >= 0 ; i--) {
                activityStack.get(i).finish();
                activityStack.remove(i);
            }
        }
    
        public int size(){
            return activityStack.size();
        }
    }
    

    2.在MainActivity中,将当前的Activity添加到栈管理中:

    protected void onCreate(Bundle savedInstanceState) {
        //将当前的Activity添加到栈管理中
        AppManager.getInstance().addActivity(this);
    }
    

      

      

  • 相关阅读:
    服务器端口
    Format(const wchar_t *,...)”: 不能将参数 1 从“const char [3]”转换为“const wchar_t *”.
    图片格式
    CreateEx
    电力谐波
    [OGeek2019]babyrop
    Simple Inject
    [GXYCTF2019]BabySQli
    [CISCN2019 华北赛区 Day2 Web1]Hack World
    极客大挑战2019
  • 原文地址:https://www.cnblogs.com/ganchuanpu/p/6481687.html
Copyright © 2020-2023  润新知