自定义Activity管理类

public class ActivityController {
      public static ArrayList<Activity> list=new ArrayList<Activity>();
      //添加栈中新增的activity
      public static void addActivty(Activity activity){
             if(!list.contains(activity)){
                  list.add(activity);
             }
      }
      //移除销毁了activity
      public static void removeActivity(Activity activity){
              list.remove(activity);
      }
      //销毁栈中的activity
      public static void finishAllActivity(){
            for(Activity currentActivity: list){
               if(!currentActivity.isFinishing()){
                currentActivity.finish();
               }
            }
      }
}
//这种做法缺点:当activity异常关闭,会activity关闭不了(该对象的堆内存地址被list中存储着,强引用),造成内存溢出

你可能感兴趣的:(自定义Activity管理类)