• 判断android应用是否在运行等方式


    /***
         * 判断当前程序是不在前台显示
         * 
         * @return
         */
        public static boolean isTopRun(Context context) {
            Boolean isTopRun = false;
            try {
                ActivityManager activityManager = (ActivityManager) context
                        .getSystemService(Context.ACTIVITY_SERVICE);
                List<RunningTaskInfo> tasksInfo = activityManager
                        .getRunningTasks(1);
                if (tasksInfo.size() > 0) {
                    String packageName = tasksInfo.get(0).topActivity
                            .getPackageName();
                    if (!TextUtils.isEmpty(packageName)
                            && packageName.startsWith(getAppPackageName())) {
                        isTopRun = true;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return isTopRun;
        }
      /***
         * 判断应用是否在运行
         * 
         * @return
         */
        public static boolean isAppRunning(Context context){
            boolean isAppRunning = false;
            try {
                ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
                List<RunningTaskInfo> list = activityManager.getRunningTasks(100);
                
                String pageName = "com.example.packagename";
                pageName = getAppPackageName();
                for (RunningTaskInfo info : list) {
                    if (info.topActivity.getPackageName().equals(pageName) || info.baseActivity.getPackageName().equals(pageName)) {
                    isAppRunning = true;
                    Log.i("SystemUtils",info.topActivity.getPackageName() + " info.baseActivity.getPackageName()="+info.baseActivity.getPackageName());
                    break;
                    }    
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            
            return isAppRunning;
        }
      /***
         * 获取当前显示的Activity
         * 
         * @return
         */
        public static void getTopActivity(Context context){
            
            ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            ComponentName cn = am.getRunningTasks(1).get(0).topActivity; 
        }
  • 相关阅读:
    TDH-hbase shell 常用命令
    WebService之基于REST机制的实现实例(Java版)
    大牛地址
    Solr的SolrCloud与Master-slave主从模式对比
    solr亿万级索引优化实践-自动生成UUID
    Solr查询中涉及到的Cache使用及相关的实现【转】
    05-spectral 图机器学习之谱分解
    03-motifs 图机器学习之motif和结构角色
    04-communities 图机器学习之社区
    02-gnp-smallworld 图机器学习之最小世界
  • 原文地址:https://www.cnblogs.com/chrono/p/3986765.html
Copyright © 2020-2023  润新知