dzikovskyy

Check if service running, Android

May 13th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private boolean isServiceRunning(Class<?> serviceClass) {
  2.  
  3.         ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
  4.         for (ActivityManager.RunningServiceInfo runningServiceInfo : activityManager.getRunningServices(Integer.MAX_VALUE)) {
  5.             if (serviceClass.getName().equals(runningServiceInfo.service.getClassName())) {
  6.                 return true;
  7.             }
  8.         }
  9.         return false;
  10.     }
Add Comment
Please, Sign In to add comment