how can I intercept a click on a device’s menu button (for example, a phone). I need something like OnMenuClick() .
OnMenuClick()
I decide it myself, like this
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_MENU||keyCode == KeyEvent.KEYCODE_BACK) && event.getRepeatCount() == 0) { // my code here... } }
You need to implement 2 things.
All click events will appear before 2.
An example is here .
You can access it when the menu opens using onMenuOpened ()
implementation of
onPrepareOptionsMenu (menu menu)
it is called every time the menu button is pressed