手机版
你好,游客 登录 注册
背景:
阅读新闻

Android判断某服务是否正在运行

[日期:2012-07-20] 来源:Linux社区  作者:centralperk [字体:大 中 小]

Android判断某服务是否正在运行:

  1. /**  
  2.         * 用来判断服务是否运行.  
  3.         * @param context  
  4.         * @param className 判断的服务名字  
  5.         * @return true 在运行 false 不在运行  
  6.         */  
  7.        public static boolean isServiceRunning(Context mContext,String className) {   
  8.            boolean isRunning = false;   
  9. ActivityManager activityManager = (ActivityManager)   
  10. mContext.getSystemService(Context.ACTIVITY_SERVICE);    
  11.            List<ActivityManager.RunningServiceInfo> serviceList    
  12.            = activityManager.getRunningServices(30);   
  13.           if (!(serviceList.size()>0)) {   
  14.                return false;   
  15.            }   
  16.            for (int i=0; i<serviceList.size(); i++) {   
  17.                if (serviceList.get(i).service.getClassName().equals(className) == true) {   
  18.                    isRunning = true;   
  19.                    break;   
  20.                }   
  21.            }   
  22.            return isRunning;   
  23.        }   
linux
相关资讯       Android编程入门 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款