The method pause
is called, when your app looses focus. On Android this happens, if you press the home button or a call is incoming.
When you return to the app, resume
gets called.
So if you switch from GameScreen
to MenuScreen
inside the pause
method, and switch from MenuScreen
to Gamescreen
inside the resum
, the MenuScreen
will never show, as it is active only when your app is in background.
What you might want to do is to switch to MenuScreen
on pause
, but on resume
don't switch back. Instead you should wait till the user presses a button Continue
and then go back to the GameScreen
.
Also, you should not call pause
or resume
yourself, those are methods called by the framework in specific situations.
EDIT:
I also noticed, that you call show
method inside the resume
method. The method show
is another method, used by the framework. It is usually called, when you switch Screen
(setScreen
in the Game
class calls hide
for the current Screnn
and show
for the new Screen
).
Also the render
method should generally not be called by you. The Game
class automatically calls the render
of the current Screen
in it's own render
. So if you set the right Screen
, the right render
method will be called.
EDIT 2:
A possible approach for you might be the following:
Inside the pause
method, save the game data, as it is possible, that the user closes the app (or Dalvik decides to close it cuase the system needs the ressources). You can also call setScreen(menuScreen)
here. This call will result in a call to actionGame.hide()
, where you might release some of the ressources used by the GameScreen
. Then it will call menuScreen.show()
where you might load ressources needed by the MenuScreen
.
When you return to the app menuScreen.resume()
will be called. You don't need to do anything here. Instead you should waint, till the menu button Continue
is pressed. Here you can load the saved data and the setScreen(gameScreen)
.
pause
is called, when your game looses focus,resume
gets called when you return to the game. So seting the screen to menu onpause
and setting it back to actiongame onresume
does not seem to make sence. Instead you should have a methodpauseGame
, which stops the logic from being updated. \$\endgroup\$