Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing a game and i've ran into some questions about saving and resuming the game. Let's say i have 10 animated sprites drawn every frame (which move side to side) and everytime i press the home button or back button and then go back to my game, it starts drawing the sprites at the starting position rather than in the position before the back/home press.

  • Do i have to save every sprite and animation position in order to achive resuming the game where i left off (using Bundle, onSaveInstanceState and onRestoreInstanceState())? Or can this be achived some other simpler way.

I'm using the lunarlander example which handles the drawing in a thread and when the user presses the home/back button(onPause) the state is saved and then reloaded on resume.But if i move all the drawing methods to SurfaceView (LunarView) and just call them from a thread(LunarView.draw()), the sprites stay in the exact same position as before the back/home button pressed without saving anything. Can someone explain why this happens? Is it something i should avoid(calling SurfaceView.draw() from a thread) or is this the anwser to my question how to save game state?

Thanks for the reply's.

Regards, J.

share|improve this question
is your initialization function called when you resume game? – Ali.S Jun 6 '11 at 14:44
ups sorry i see now why this is happening.. when resume was called the initialization was called also.. stupid me :S I see now that the LunarLander example saves it's state only to save the users state even if u kill the game's process not only if u press the home button. – Jernej Jun 6 '11 at 15:03
exactly my point. – Ali.S Jun 6 '11 at 15:08
@Gajet Add it as an answer so the OP can accept it. – Anko Jun 18 '11 at 13:12

If I have to guess I think you are calling initialize function every time you try resuming the game. You just have to avoid calling it when the game is resumed. Remember there is a diffrence between launching game and resuming it, and initilize is only used for launching game.

share|improve this answer
how can you check if this is happening? is it the views constructor or its onCreate() you dont want to call on resume? or maybe both? cus I have this problem with the classes that get their x and yvalue set in their constructor. – Max Sep 29 '12 at 14:30
@max as far as I know different events are called for each of resuming and initializing, but I don't know what are those events. – Ali.S Sep 29 '12 at 16:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.