views:

88

answers:

2

I want to be able to automatically unpause my app when the user exits from the options menu. (unless, of course, they have selected pause...)

Handling it onOptionsMenuClosed works fine for the top level menu but is not called for a submenu. The higher level onPanelClosed does not appear to be called either.

I can detect when they enter the menu and if they make a selection but not if they just hit the menu button to exit.

I could rewrite the whole submenu to use a dialog but I'd rather not if it can be avoided.

Does anyone have any suggestions?

A: 

You can override onKeyDown and implement a menu yourself when the menu button is detected.

schwiz
It's certainly an option but it shouldn't really be necessary to circumvent the whole menu system to do this. (And possibly a bit risky since it's clearly not what the designers of Android expect you to do)
FixerMark
I don't see why not, how else can you have a highly stylized menu? I think its the best way to go especially for a game. You could even start a new activity for result with a transparent darkened background when you detect menu pressed.
schwiz
Note that you can exit the menu just by tapping anywhere on the screen, you don't necessarily have to hit the menu button again, so this won't work for all cases.
Mayra
Mayra you would have to handle that logic yourself. If you do it with an activity overlay method that I mentioned in the comment above you would just call finish when menu is pressed in that activity.
schwiz
Ok, but 9 times out of 10, implementing your own menu is the wrong way to go. If you have some highly stylized app like a game it might be ok, but generally Android users expect the menu button to behave a specific way, and you will just confuse them if you do something different.
Mayra
Thanks for the suggestions. I may have to look into implementing the menu as an overlay activity.
FixerMark
+1  A: 

You could override the onkeydown , set a flag to check if the menu is shown or not do you thing then return super.onKeyDown(keyCode, event); .

You could check if menu if on screen on every keydown.Keep in mind that other buttons (Back , search and home and touch on other part of the screen closes the menu.) .With other buttons you may do handle them but home botton and finger tap cannot be override.

If i was you i whould forget the @override on onkeydown option for that purpose

But you can have 6 menu buttons the 6th called "More" and that could create a custom dialog with more options that you can handle

weakwire