code: private static void destroyService() {
          Thread thread = DESTROY_THREAD;
          if (thread == null) {
              thread = new Thread() {
                  @Override
                  public void run() {
                      try {
                          // we wait 5000ms, because the service maybe can use
                          Thread.sleep(5000);
                          dispose();
                      } catch (InterruptedException e) {
                          //e.printStackTrace();
                      }
                      DESTROY_THREAD = null;
                  }
              };
              thread.setDaemon(true);
              DESTROY_THREAD = thread;
              thread.start();
          }
      }
docs: Destroy Service After 5 seconds run