title: Flashlight with strobe: strobe doesn’t turn OFF
body: <p>I am trying to create a flashlight app with a strobe effect. My goal is that I can turn ON/OFF the flashlight with a switch Btn and increase the strobe frequency with a seekbar. If the seekbar value is 0 and the switch Btn is ON the flashlight should be ON (without any strobe). But right now it is still blinking (strobe effect ON) if the seekbar value is 0. Do you know how I can change that?
  Here is some of the code which I think is important (I really can't find the part which keeps the stobe effect still on:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      mySwitch = (Switch) findViewById(R.id.mySwitch);
  
      //listener to check changes in state
      mySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              turnOnOff(isChecked);
          }
      });
      skBar = (SeekBar) findViewById(R.id.seekBar);
      skBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
              freq = progress;
          }
          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
          }
          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
          }
      });
  }
  @Override
  protected void onResume() {
      super.onResume();
      try {
          cam = Camera.open();
          camParams = cam.getParameters();
          cam.startPreview();
          hasCam = true;
      }catch(Exception e){
      }
  }
  private void turnOnOff(boolean on){
      if(on) {
          if(freq != 0){
              sr = new StroboRunner();
  
              t = new Thread(sr);
              t.start();
              return;
          }else{
              camParams.setFlashMode(Parameters.FLASH_MODE_TORCH);
          }
      }else if(!on){
          if(t != null){
              sr.stopRunning = true;
              t =null;
              return;
          }else{
              camParams.setFlashMode(Parameters.FLASH_MODE_OFF);
          }
      }
      cam.setParameters(camParams);
      cam.startPreview();
  }
  private class StroboRunner implements Runnable {
  
      boolean stopRunning = false;
      @Override
      public void run() {
          Camera.Parameters paramsOn = cam.getParameters();
          Camera.Parameters paramsOff = camParams;
          paramsOn.setFlashMode(Parameters.FLASH_MODE_TORCH);
          paramsOff.setFlashMode(Parameters.FLASH_MODE_OFF);
          try {
              while (!stopRunning) {
                  cam.setParameters(paramsOn);
                  cam.startPreview();
                  Thread.sleep(100 - freq);
                  cam.setParameters(paramsOff);
                  cam.startPreview();
                  Thread.sleep(100 - freq);
  
              }
          }catch(Exception e){
              }
          }
      }
  
  }
  </code></pre>