Skip to content

Instantly share code, notes, and snippets.

@dekzitfz
Created August 1, 2016 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekzitfz/1d4a5f7154e92429a6da6202ac2078d4 to your computer and use it in GitHub Desktop.
Save dekzitfz/1d4a5f7154e92429a6da6202ac2078d4 to your computer and use it in GitHub Desktop.
check if an android service is running or not
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment