我需要知道队列中的所有intentservices是否被"消耗",或者另一种方法是找出它是否还在做什么,以便在所有服务都停止运行之前我不会继续.有任何想法吗?
我想检查服务是否正在运行l写了这段代码
public class startServiceOrNo {
public static void startServiceIfItsNotRuning(Class<?> class1, Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (class1.getName().equals(service.service.getClassName())) {
Lg.d("servisstart SERVICE ALREADY START" + class1.getName());
return;
}
}
Lg.d("servisstart SSERVICE NEW SERVIS " + class1.getName());
context.startService(new Intent(context, class1));
}
Run Code Online (Sandbox Code Playgroud)
并使用它startServiceOrNo.startServiceIfItsNotRuning(OfflineChopsMonitor.class,this)
如果我检查来自一个类的服务它的工作,但如果我检查来自不同类的相同服务,它的检查不起作用