code: public static void stop(Service service) {
      if (service != null) {
        Service.STATE state = service.getServiceState();
        if (state == Service.STATE.STARTED) {
          service.stop();
        }
      }
    }
docs: Stop a service.
  
  Do nothing if the service is null or not in a state in which it can be/needs to be stopped.
  
  The service state is checked <i>before</i> the operation begins.
  This process is <i>not</i> thread safe.
  @param service a service or null