Got solution.
What you should do is, write all the code like following in onBackPressed
. I merge two methods code in one method.
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
myparas = mycamera.getParameters();
myparas.setFlashMode(Parameters.FLASH_MODE_OFF);
mycamera.setParameters(myparas);
mycamera.stopPreview();
flashon = false;
if (mycamera != null) {
mycamera.release();
mycamera = null;
}
Log.d("Camera","Back Pressed");
}
And remove all the code from onStop()
and onPause()
method. Because when you press Home
key, it calls first onPause()
and then onStop()
. I implement your code and worked fine for me.