I have an activity where I flag full-screen once the orientation changes, problem is when you are currently in full-screen and you press the back button it will go back to the previous fragment in full-screen, which I do not want. I added this code but it doesn't seem to be called:
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
//do what ever you want here
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getActivity().getActionBar().show();
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
Toast.makeText(getActivity().getBaseContext(), "backbuttonpressed", Toast.LENGTH_LONG).show();
getActivity().finish();
return true;
}
return super.getActivity().onKeyDown(keyCode, event);
}
Maybe this will work for you: