The method parameters were two
AS provides shortcuts to the full path name of the class class 1.className Service "class name package name +", the following
2.context context object
invokes this method returns true if it is running, If false is not running.
Method code is as follows:
public static boolean isServiceRunning(String className, Context context) {
//进程管理者
ActivityManager manager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
//获取进程中正在运行的服务集合
List<ActivityManager.RunningServiceInfo> runningservice = manager.getRunningServices(1000);
//遍历
for (ActivityManager.RunningServiceInfo runningServiceInfo : runningservice) {
//获取正在运行的服务的标识
ComponentName service = runningServiceInfo.service;
//获取正在运行的服务的全类型
String name = service.getClassName();
//判断
if (name.equals(className)) {
return true;
}
}
return false;
}