when you start camera set boolean isCamaraOn = true;
and when camera is on and you press back button
then
if(!isCameraOn){//go in only if camera is off
if (keyCode == KeyEvent.KEYCODE_BACK) {
getActivity().finish();//Line-9
}
}
here you can set isCamaraOn to false;
try this, hope works for you