activity 점프 후finish 애니메이션으로 인한 블랙스크린 구제

19711 단어 android금전출납부
뛰기 전에부모activity를 appManager에 추가합니다.finish를 직접 실행하지 않고, 하위 activity에 적합한 위치에 있습니다.예를 들면 다음과 같습니다.
getWindow().getDecorView().post(new Runnable() {
 //TODO    activity
});
아니면 finish자 acvitity 때 복사.
@Override
public void finish() {
 //TODO    activity
   super.finish();
}

AppManager 호출.finishActivityFromName (activity.class.getSimpleName ())) 은 부모 activity를 제거하고 자신의finish () 방법을 호출합니다.
/**     Activity    */
public class AppManager {
   private static Stack<Activity> activityStack;
   private static AppManager instance;

   private AppManager() {
   }

   /**
    *     
    */
   public static AppManager getAppManager() {
      if (instance == null) {
         instance = new AppManager();
      }
      return instance;
   }

   /**
    *   Activity   
    */
   public void addActivity(Activity activity) {
      if (activityStack == null) {
         activityStack = new Stack<Activity>();
      }
      activityStack.add(activity);
   }

   /**
    *     Activity(          )
    */
   public Activity currentActivity() {
      Activity activity = activityStack.lastElement();
      return activity;
   }

   /**
    *     Activity(          )
    */
   public void removeActivity() {
      Activity activity = activityStack.lastElement();
      removeActivity(activity);
   }

   /**
    *      Activity
    */
   public void removeActivity(Activity activity) {   
      if (activity != null) {
         activityStack.remove(activity);
         activity.finish();
         activity = null;
      }
   }

   /**
    *        Activity
    */
   public void finishActivity(Class> cls) {
      for (Activity activity : activityStack) {
         if (activity.getClass().equals(cls)) {
            if (activity != null) {
               activity.finish();
               activity = null;
            }
         }
      }
   }
   
   /**
    *        activity      
    */
   public boolean containActivity(Class> cls) {
        for (Activity activity : activityStack) {
            if (activity.getClass().equals(cls)) {
                if (activity != null) {
                   return true;
                }
            }
        }
        return false;
    }
   /**
    *     Activity
    */
   public void finishAllActivity() {
      if (activityStack==null) {
         return;
      }
      for (int i = 0, size = activityStack.size(); i < size; i++) {
         Activity activity = activityStack.get(i);
          if (null != activity) {
              activity.finish();
              activity = null;
         }
      }
      activityStack.clear();
   }

   /**
    *        activity
    */
   public void removeActivityFromName(String activityName) {
      if (activityStack==null || TextUtils.isEmpty(activityName)) {
         return;
      }
      for (int i = 0; i < activityStack.size(); i++) {
         if (activityName.equals(activityStack.get(i).getClass().getSimpleName())){
            activityStack.get(i).finish();
         }
      }
   }
   /**
    *       activity   activity
    */
   public void finishAllExcept(String activityName) {
      if (activityStack==null || TextUtils.isEmpty(activityName)) {
         return;
      }
      for (int i = 0; i < activityStack.size(); i++) {
         if (activityName.equals(activityStack.get(i).getClass().getSimpleName())){

         }else{
            activityStack.get(i).finish();
         }
      }
   }
}

좋은 웹페이지 즐겨찾기