I notice that when implementing onPrepareOptionsMenu() in my activity - the first press works good - the callback from onPrepareOptionsMenu() starts. but when it still visible(open some dialog) and I want the second press to close it(trigger the callback to close the dialog) - the second press on the menu button doesn't triggers onPrepareOptionsMenu(). don't sure why
This is how I implement it:
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (onDoneListener != null) {
onDoneListener.OnDone();
}
return false;
}
EDIT1:
I added the next function after the commenter help but still no luck. The OnKeyDown() also not receiving the next menu button press. It looks like the menu button doesn't get events until I'm pressing the back button. Here is the code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
if (onDoneListener != null)
onDoneListener.onDone();
}
return super.onKeyDown(keyCode, event);
}
I also tried to return true and false but not luck.
What you are seeing is the exact intended behavior of OnPrepareOptionsMenu
. It runs before the menu is shown, not after.