I have a game with 2 activities: one is Startup, with a button guide user to the other one, the Game.
In Game, user my press back to return to Startup. How to start the previous Game when user click the button again, without calling its onCreate()?
The Game is started by startActivity().
Much of job is done is Game view, so I want to keep the game state without initializing again.
I have tried singleTop/singleTask and intent flags with FLAG_ACTIVITY_REORDER_TO_FRONT. They both trigger Game’s onCreate() called again.
Thanks.
By default, the back button finishes the Activity, so you can’t “return” to it. You need to save your game state, and then restore game state from within onCreate when the user re-enters the game.
Alternatively, you can just override the back button to show a pop-up list of options (exit, new game, see high scores, etc), so that the game itself isn’t popped off the top. Then another hit of the back button (or resume game) removes that pop-up menu, and “onResume()” is called instead of “onCreate()” (according to the Activity Lifecycle).