/**
* 用来判断服务是否运行.
* @param context
* @param className 判断的服务名字
* @return true 在运行 false 不在运行
*/
public static boolean isServiceRunning(Context mContext,String className) {
boolean 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;
}
android判断某服务是否正在运行
最新推荐文章于 2023-10-06 16:20:57 发布
本文介绍了一个用于检测Android应用中特定服务是否正在运行的方法。通过获取系统当前运行的服务列表,并检查这些服务中是否存在指定的服务名来判断该服务是否处于活动状态。

779

被折叠的 条评论
为什么被折叠?



