Skip to content

Instantly share code, notes, and snippets.

@donrokzon
Created June 23, 2017 07:43
Show Gist options
  • Select an option

  • Save donrokzon/735ac8da5b5f690253dae5a6ff95cbca to your computer and use it in GitHub Desktop.

Select an option

Save donrokzon/735ac8da5b5f690253dae5a6ff95cbca to your computer and use it in GitHub Desktop.
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
isMyServiceRunning(MyService.class)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment