public class ServiceUtil {
/**
* 判断一个服务是否还在运行
*
* @param serviceName
* 服务的全限定名
*/
public static boolean isServiceRunning(Context context, String serviceName) {
boolean isRunning = false;
// ActivityManager可以管理activity和service
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
// 获取运行的服务
List<RunningServiceInfo> runningServices = am.getRunningServices(1000);
for (RunningServiceInfo rsf : runningServices) {
String name = rsf.service.getClassName();
if (serviceName.equals(name)) {
isRunning = true;
break;
}
}
return isRunning;
}
}
/**
* 判断一个服务是否还在运行
*
* @param serviceName
* 服务的全限定名
*/
public static boolean isServiceRunning(Context context, String serviceName) {
boolean isRunning = false;
// ActivityManager可以管理activity和service
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
// 获取运行的服务
List<RunningServiceInfo> runningServices = am.getRunningServices(1000);
for (RunningServiceInfo rsf : runningServices) {
String name = rsf.service.getClassName();
if (serviceName.equals(name)) {
isRunning = true;
break;
}
}
return isRunning;
}
}