判断某个界面是否在前台

来源:互联网 发布:英语造句软件下载 编辑:程序博客网 时间:2024/06/06 12:41
 /**      * 判断某个界面是否在前台      *       * @param context      * @param className      *            某个界面名称      */      public static boolean isForeground(Context context, String className) {          if (context == null || TextUtils.isEmpty(className)) {              return false;          }          ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);          List<RunningTaskInfo> list = am.getRunningTasks(1);          if (list != null && list.size() > 0) {              ComponentName cpn = list.get(0).topActivity;              if (className.equals(cpn.getClassName())) {                  return true;              }          }         return false;      }  
0 0
原创粉丝点击