title: How to make flashlight Blink in android
body: <p>In my code after exiting from thread the flash light is still on. I can't   understand the logical error. How can I turn the flash light off at the end of the thread?</p>
  
  <pre><code>Thread thread = new Thread((new Runnable() {
      @Override
      public void run() {
          SystemClock.sleep(200);
          int led = 1;
          while (blink_enabler) { 
             if (led == 1) {
                  params = cam.getParameters();
                  params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
                  cam.setParameters(params);
                  cam.startPreview();
                  led = 0;
              } else {
                  params = cam.getParameters();
                  params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
                  cam.setParameters(params);
                  cam.stopPreview();
                  led = 1;
              }
              SystemClock.sleep(1000);
          }
          params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
          cam.stopPreview();
      }
  }));
  </code></pre>