title: Flash not being turned off on button press(Flashlight App)
body: <p>I have 3 buttons on the UI. <code>On, Off and SOS</code>(flash at repeated intervals). If I press On and then the Off button the flash turns off as expected.But if I press SOS(it flashes as expected at regular intervals) and then Off it refuses to stop flashing. The code is as follows:</p>
  
  <pre><code>SOSbutton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                      try {
                  SOSon = true;
                  startSOS();
                  onSOSPress();
              } catch (Exception ex) {
                  throw ex;
              }
              }
          });
  void onSOSPress() {
              try {
                Flashlight flashlight=new Flashlight();
                  SOSon = true;
                     flashlight.Flashthread = new Thread(new Runnable() {
                              @Override
                              public void run() {
                                  for (int i = 0; i &lt; System.currentTimeMillis(); i++) {
                                      while (!FlashThreadStop) {
                                          if (FlashOn) {
                                             myParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
                                              try {
                                                  myCamera.setParameters(myParameters);
                                              }
                                              catch (Exception ex)
                                              {
                                                  //logger.log(Level.SEVERE, "an exception was thrown", ex);
                                              }
                                             myCamera.stopPreview();
                                             FlashOn = false;
                                          } else {
                                              TurnOnFlash();
                                          }
                                          try {
                                              Thread.sleep(100);
                                          } catch (InterruptedException e) {
                                              e.printStackTrace();
                                          }
                                      }
  
                                  }
                              }
                          });
                         flashlight.Flashthread.start();
              } catch (Exception ex) {
                  throw ex;
              }
          }
  </code></pre>
  
  <p>and the <strong>TurnOff mechanism</strong> is as follows:</p>
  
  <pre><code>off.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  if (FlashOn) {
  
                      // turn off flash
                      TurnOffFlash();
  
                  } 
              }
          });
  
  private void TurnOffFlash() {
  
          if (FlashOn) {
  
              if (myCamera == null || myParameters == null) {
                  return;
  
              }
  
              myParameters = myCamera.getParameters();
              myParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
              myCamera.setParameters(myParameters);
              myCamera.stopPreview();
              FlashOn = false;
  
          }
      }
  void endSOS(){
          FlashThreadStop=true;
      }
      void startSOS(){
          FlashThreadStop=false;
      }
  </code></pre>
  
  <p><strong>EDIT:</strong> The method onSOSPress() has been updated to reflect the working SOS mode(OFF button works now)</p>