I have a service which returns START_STICKY on #onStartCommand() and it is being started in my MainActivity's #onCreate() method. When i close my app, Service is being destroyed and it starts itself again. However, when it starts itself, ActivityManager can't find it. So there are 2 instance of my service running..
I use this code to check is service dead, it returns true everytime even if it lives after service starts itself.
public static boolean isServiceDead(Context context) {
final ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo runningServiceInfo : am.getRunningServices(Integer.MAX_VALUE))
if (runningServiceInfo.service.getClassName().equals(LockerService.class.getName()))
return false;
return true;
}