code: public void stop() {
          if (session == null) {
              return;
          }
  
          sync.lock();
  
          try {
              if (session == null) {
                  return;
              }
  
              onBeforeStop();
  
              session s = session;
              session = null; // stop alerts loop and session methods
  
              // guarantee one more alert is post and detected
              s.post_session_stats();
              try {
                  // 250 is to ensure that the sleep is bigger
                  // than the wait in alerts loop
                  Thread.sleep(ALERTS_LOOP_WAIT_MILLIS + 250);
              } catch (InterruptedException ignore) {
              }
  
              if (alertsLoop != null) {
                  try {
                      alertsLoop.join();
                  } catch (Throwable e) {
                      // ignore
                  }
              }
  
              resetState();
  
              s.delete();
  
              onAfterStop();
  
          } finally {
              sync.unlock();
          }
      }
docs: This method blocks during the destruction of the native session, it
  could take some time, don't call this from the UI thread or other
  sensitive multithreaded code.