【安卓笔记】是否执行测试服务

/**
	 * 无论是背景推断服务
	 * 
	 * @param context
	 *            Context
	 * @param className
	 *            推断的业务名称
	 * @return true 在执行 false 未进行
	 */
	public static boolean isServiceRun(Context mContext, String className) {
		boolean isRun = false;
		ActivityManager activityManager = (ActivityManager) mContext
				.getSystemService(Context.ACTIVITY_SERVICE);
		List<ActivityManager.RunningServiceInfo> serviceList = activityManager
				.getRunningServices(40);
		int size = serviceList.size();
		for (int i = 0; i < size; i++) {
			if (serviceList.get(i).service.getClassName().equals(className) == true) {
				isRun = true;
				break;
			}
		}
		return isRun;
	}
需要注意的是classname必须完成一个服务名称,这包名.类名
posted @ 2015-06-08 13:57  mengfanrong  阅读(134)  评论(0编辑  收藏  举报