title: Why does the camera flash light not turn off on Samsung Galaxy Ace?
body: <p>I tried this code to turn on/off the flash light:</p>
  
  <p><a href="https://stackoverflow.com/questions/6939816/turn-on-off-camera-led-flash-light-in-samsung-galaxy-ace-2-2-1-galaxy-tab">Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 &amp; Galaxy Tab</a></p>
  
  <p>and it worked for me, I mean it turned on the flash but now I can't to turn off the flash after press off button.</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class Main extends Activity
  {
  private Camera camera;
  private Button buttonOn;
  private Button buttonOff; 
  
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.main);
  
      buttonOn = (Button) findViewById(R.id.buttonOn);
      buttonOff = (Button) findViewById(R.id.buttonOff);
  
      buttonOn.setOnClickListener(new OnClickListener()
      {
          @Override
          public void onClick(View v)
          {
              try {
                   turnOn();
              } catch (Exception ex) {
  
              }
          }
      });
  
      buttonOff.setOnClickListener(new OnClickListener()
      {
          @Override
          public void onClick(View v)
          {
              try {
                   turnOff();
              } catch (Exception ex) {
  
              }
          }
      }); 
  }
  
  @Override
  public void onPause(){
      super.onPause();
      if( camera != null )
         {
            camera.release();
            camera = null;
         }
         super.onPause(); 
  }
  
  @Override
  public void onResume(){
      super.onResume();               
  } 
  
  @Override
  public void onStart(){
      super.onStart();
  }
  
  @Override
  public void onStop(){
      super.onStop();
  }
  
  @Override
  public void onDestroy(){
      super.onDestroy();
  }
  
  @Override
  public void onRestart(){
      super.onRestart();
  }   
  
  private void turnOff()
  {               
          camera.stopPreview();
          camera.release();
  
     }
  
   private void turnOn() 
     {
              camera = Camera.open();  
              camera.startPreview();
              camera.autoFocus(new AutoFocusCallback() {
                          public void onAutoFocus(boolean success, Camera camera) {
                          }
                      });
  
              Parameters params = camera.getParameters();
              params.setFlashMode(Parameters.FLASH_MODE_ON);
              camera.setParameters(params);
  
              params = camera.getParameters();
              params.setFlashMode(Parameters.FLASH_MODE_OFF);
              camera.setParameters(params);
  
     }
  }
  </code></pre>
  
  <p>In this way the led turns on after I click on buttonOff first. If I click on buttonOn before click on buttonOff it doesn't work. Once I do this then the led is on all the time but I can't turn it off when I click on buttonOff. </p>
  
  <p>If I put this part of code:</p>
  
  <pre><code>            params = camera.getParameters();
              params.setFlashMode(Parameters.FLASH_MODE_OFF);
              camera.setParameters(params);
  </code></pre>
  
  <p>on 'turnOff' function instead where it is now, then the led is on only around 5 seconds.
  I tried using thread.sleep between both parts: Flash mode on and Flash mode off as I read in the post but it didn't work either.</p>
  
  <p>Any idea about this?</p>
  
  <p>Thanks in advanced.</p>