灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3893回复:0

android判断某服务是否正在后台运行

楼主#
更多 发布于:2012-09-25 14:37

/**
       * 用来判断服务是否后台运行
       * @param context
       * @param className 判断的服务名字
       * @return true 在运行 false 不在运行
       */
      public static boolean isServiceRunning(Context mContext,String className) {
          booleanV IsRunning = false;
          ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
          List<ActivityManager.RunningServiceInfo> serviceList   = activityManager.getRunningServices(30);
         if (!(serviceList.size()>0)) {
              return false;
          }
          for (int i=0; i<serviceList.size(); i++) {
              if (serviceList.get(i).service.getClassName().equals(className) == true) {
                  IsRunning = true;
                  break;
              }
          }
          return IsRunning ;
      }

喜欢0 评分0
游客

返回顶部