code: public static boolean isServiceRunning(Context context, Class<? extends Service> service, int maxCheckCount) {
          if (context == null || service == null) {
              return false;
          }
  
          ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
          List<RunningServiceInfo> list = manager.getRunningServices(maxCheckCount);
          for (RunningServiceInfo info : list) {
              if (service.getCanonicalName().equals(info.service.getClassName())) {
                  return true;
              }
          }
          return false;
      }
docs: Checks if the specified service is currently running or not.
  @param context the context.
  @param service the {@link java.lang.Class} of the service.
  @param maxCheckCount maximum value of the running service count for this check.
  @return true if the service is running, false otherwise.