Skip to content

Instantly share code, notes, and snippets.

@kbshl
Created November 25, 2016 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbshl/ee0c4fa286537df55275cea011e6e0a7 to your computer and use it in GitHub Desktop.
Save kbshl/ee0c4fa286537df55275cea011e6e0a7 to your computer and use it in GitHub Desktop.
public class HomeActivity extends Activity {
...
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode){
case KeyEvent.KEYCODE_BACK:
if (action == KeyEvent.ACTION_DOWN) {
Log.v("myApp", "Back button pressed.");
return true;
}
default:
return false;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment