title: how to stop a running thread with button toggle (android app)
body: <p>I finally got my app working, i just have one issue which i would like to correct.</p>
  
  <p>I have a button which controls a thread that runs a couple function in the background. The functions in the background eventually stop the thread whenever a certain value is reached. What i am having issues doing is pressing that same button again to just stop the thread manually. Currently I can only start the thread and wait for itself to finish. I am able to do other things in the app, so the thread is running on its own, i just want to kill it manually.</p>
  
  <pre><code>    public void onMonitorClick(final View view){
      if (isBLEEnabled()) {
          if (!isDeviceConnected()) {
                  // do nothing
          } else if (monitorvis == 0) {
              showMonitor();
              DebugLogger.v(TAG, "show monitor");
              //monitorStop = 4;
              Kill.runThread();         // I want a function here that would kill the 
                                       // thread below, or is there something that 
                                       // can be modified in runThread()?
                                       // I did try Thread.Iteruppted() without luck
              shutdownExecutor();
  
          } else if (monitorvis == 1) {
              hideMonitor();
              DebugLogger.v(TAG, "hide monitor");
              monitorStop = 0;
              runThread(); //The running thread that works great on its own
  
          }
      } 
      else {
          showBLEDialog();
      }
  }
  
  
  
  private void runThread() {
  
      new Thread() {
          int i;
          public void run() {
              while (monitorStop != 3) {  //This is where the thread stops itself 
                  try {
                      runOnUiThread(new Runnable() {
  
                          @Override
                          public void run() {
                              ((ProximityService.ProximityBinder) getService()).getRssi();
                              rssilevel = ((ProximityService.ProximityBinder) getService()).getRssiValue();
                              mRSSI.setText(String.valueOf(rssilevel) + "dB");
                              detectRange(rssilevel);
                          }
                      });
                      Thread.sleep(750);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
      }.start();
  }
  </code></pre>