activityManager.getRunningServices(Integer.MAX_VALUE);
This method returns a list which includes service which is stopped manually.
Settings > Applications > Running services
activityManager.getRunningServices(Integer.MAX_VALUE);
This method returns a list which includes service which is stopped manually.
Settings > Applications > Running services
All the approaches using onDestroy or onSometing events or Binders or static variables will not work reliably because as a developer you never know, when Android decides to kill you process or which of the mentioned callbacks are called or not. Please note the "killable" column in the lifecycle events table in Android documentation.
//use this code to check your service is running or not
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.example.MyService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}