Skip to content

Instantly share code, notes, and snippets.

@alvareztech
Last active December 24, 2015 12:08
Show Gist options
  • Save alvareztech/6795219 to your computer and use it in GitHub Desktop.
Save alvareztech/6795219 to your computer and use it in GitHub Desktop.
Android: Detect physical buttons, back pressed, menu pressed.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// MENU pressed
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
// super.onBackPressed(); // quit immediately
openQuitDialog();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment