I am trying to catch the back button event for Android. I know that there is already a lot about it, but my code does not work as the given examples. Here is my code snippet to capture the event:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode == KeyEvent.KEYCODE_BACK){
Log.d(TAG, "back key captured");
return true;
}
return super.onKeyDown(keyCode, event);
}
I also tried this:
@Override
public void onBackPressed(){
Log.d(TAG, "in onBackPressed");
finish();
}
LogCat exit that was fired or event is not displayed. Does anyone know the reason for this?
Thank.
coder source
share