BaseActivity

作者: Mayo酱 | 来源:发表于2017-09-22 21:10 被阅读0次

    获得当前活动名称

    getClass.getSimpleName();
    

    退出应用

    public class ActivityCollector {
        public static List<Activity>activities=new ArrayList<Activity>();
    
        public static void addActivity(Activity activity){
            activities.add(activity);
        }
        public static void removeActivity(Activity activity){
            activities.remove(activity);
        }
        //测试finishAll()方法在ThirdActivity中
        public static void finishAll(){
            for (Activity activity:activities) {
                if(!activity.isFinishing()){
                    activity.finish();
                }
            }
        }
    }
    
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ActivityCollector.addActivity(this);//向List添加活动
        }
    
        @Override
        protected void onDestroy() {
            super.onDestroy();
            ActivityCollector.removeActivity(this);//从List移除活动
        }
    
    //销毁所有Activity后可以加上结束当前进程的方法
    public void onClick(View v) {
                    ActivityCollector.finishAll();//销毁所有活动
                }
    

    相关文章

      网友评论

        本文标题:BaseActivity

        本文链接:https://www.haomeiwen.com/subject/cjqqextx.html