In my SystemBroadcastReceiver i want to check weather by BG service is running or not, If it was already running then i will wait it to be completed.
I want both my services should run differently and on main thread only
In my SystemBroadcastReceiver i want to check weather by BG service is running or not, If it was already running then i will wait it to be completed.
I want both my services should run differently and on main thread only
Use below method to check service is running or not:
public static boolean isMyServiceRunning(Class<?> serviceClass, Context ctx) {
final ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
This work fine for my application