I don't know how to handle camera flash in my app. My app has a button which turn camera flash on and off, everything is OK and app working fine, even when pressing back button and coming back to app it works fine.
But when i press HOME button when app is running, and then come back to my app, when I press ON and OFF button it crashes(force close). I think the problem is in app's life cycle, but I don't know how to fix it.
in onStop() method, I use this code:
@Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.stopPreview();
camera.release();
}
and turn on the flash in onCreate() method using this code:
Parameters p = camera.getParameters();
if (!isLightOn) {
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLightOn = true;
}