I have created an android app which will allow the user to switch on and switch off the flash light by pressing a button. If the user switch on the flash light and change the orientation, the light is getting switched off. Why this is happening. Please see the code below which i used.
cam = Camera.open();
final Parameters p = cam.getParameters();
torch_switch = (Button)findViewById(R.id.torch_switch);
torch_switch.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(isLightOn) {
torch_switch.setText("Switch ON Torch");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
cam.setParameters(p);
cam.stopPreview();
isLightOn = false;
} else {
torch_switch.setText("Switch OFF Torch");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
isLightOn = true;
}
}
});