zoukankan      html  css  js  c++  java
  • android 判断app是否处于前台

    逻辑是获取系统的运行栈,处于栈顶的就是处于前台的app,然后对比包名,不同则表示app处于后台,反之,则表示app处于前台.

    /**
         * app是否在后台
         *
         * @param context
         * @return true 是 false 不是
         */
        public static boolean isBackground(Context context) {
            ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
            if (!tasks.isEmpty()) {
                ComponentName topActivity = tasks.get(0).topActivity;
                StaticMethod.debugEMSG(topActivity.getPackageName() + " : " + context.getPackageName());
                if (!topActivity.getPackageName().equals(context.getPackageName())) {
                    return true;
                }
            }
            return false;
        }
    

      

  • 相关阅读:
    移动端调试解决方案-转载
    移动端调试工具-Weinre
    css颜色大全-转载
    目录
    多版本python import 问题解决方案
    annoy安装
    word2vec
    GBDT
    Adaptive Boosting
    融合模型Aggregation
  • 原文地址:https://www.cnblogs.com/sun-yang-/p/5166720.html
Copyright © 2011-2022 走看看