1. 程式人生 > >判斷一個Activity是否處於棧頂

判斷一個Activity是否處於棧頂

/**
     * 
     * 判斷activity是否處於棧頂
     * @return  true在棧頂false不在棧頂
     */

    private boolean isMainActivityTop(Activity XXXActivity){

   ActivityManager manager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
   List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);

   if (runningTaskInfos != null && !runningTaskInfos.isEmpty())
   String name = runningTaskInfos.get(0).topActivity.getClassName();

      return name.equals(XXXActivity.class.getName());

    }