You can't guarantee that you will get back to that instance of GameActivity you need to save the game state somehow, and make your GameActivity able to resume from that saved state Make sure you understand the Activity lifecycle The instance of your activity can be killed at any time when it isn't visible, so you need to save state at the proper point ( onSaveInstanceState ).
You can't guarantee that you will get back to that instance of GameActivity you need to save the game state somehow, and make your GameActivity able to resume from that saved state. Make sure you understand the Activity lifecycle. The instance of your activity can be killed at any time when it isn't visible, so you need to save state at the proper point (onSaveInstanceState).
I am handling save state correctly when the Activity is killed. I really want to know if I can detect if an activity has been killed, because if it has not been killed then I would like to redisplay it without re-initializing everything. Is this not possible or recommended?
– skaz Jan 17 at 21:04 Take a game like Robo Defense. You hit "back" while in the game and get to the main menu. Then you hit "resume game" and you go back to the state you were at.Do you believe in all cases that the author saves the full state and then reloads it?
Thanks! – skaz Jan 17 at 21:05 1 I've spent a great deal of time reading the above links for the purpose of understanding your very question, so i'd advise setting up a couple of test projects to test each step you uncover as you'll keep coming back to them. You might also want to check out developer.android.
Com/guide/topics/testing/index. Html as this allows you to test some of the different occasions that you can end up in. Such as when your activity is dropped for an incoming call etc. And its on occasions like those that it pays to have tested up front.
– Emile Jan 17 at 21:16 1 @skaz I see... No, probably not in all cases but you have to assume that can happen any time. You probably want to use a launch flag on your game activity, like singleInstance that causes the existing instance to be used if there is one. See developer.android.
Com/guide/topics/fundamentals. Html#acttask for details. Also, you probably need to override onBack to prevent it from finishing the activity.
Just launch the title screen instead. – Mayra Jan 17 at 21:18 Don't use singleInstance, it has deep meaning for activity task management that you don't want. – hackbod Jan 177 at 2:36.
The answer I would give is: don't do this. Finishing an activity (which is what happens by default when you press back) does finish that activity. You don't return to it.
If you want to allow the user to press back to pause your game into a menu, capture the back key with onBackPressed(), and instead of allowing the default behavior of finishing the activity, simply show your menu in-place in that activity. Generally I think for games making the core game UI be one activity that is the base activity launched for the app makes more sense than trying to split it into activities. Games are just special that way.
When they start up a game, I push a GameActivity onto the stack. Then if the user hits the physical back button the phone, the application goes back to the TitleActivity, as I intend it. However, I need a way to allow the user to resume the game at this point, but I don't know how to get back to htat instance of the GameActivity.
Any help is appreciated.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.