I’m making a game using OpenGL. If I press the Menu button, the game should be paused and then the option menu open, but when I press the menu button, the game pauses and the option menu opens just for a split second and then automatically closes itself. Here is my code:
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {//klo press tombol menu hrs dipause
SFEngine.newGame = false;
gameView.onPause();
openOptionsMenu();
}
return true;
}
What is causing my menu to close?
update :
public boolean onPrepareOptionsMenu(Menu menu){
gameView.onPause();
return true;
}
does onPrepareOptionMenu also been called when the game started?
I suspect that android may be opening the options menu in some kind of internal
onClickcallback, which coincides with youronKeyUp. That causes twoopenOptionsMenucalls to execute at about the same time, and the second one closes the menu.Perhaps it would be better to let android Activity manage the options menu instead of stealing the keypress? You can pause the gameView in
onPrepareOptionsMenu, and in that case you don’t have to steal the keypress.