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.

  • \$\begingroup\$ is your initialization function called when you resume game? \$\endgroup\$
    – Ali1S232
    Jun 6, 2011 at 14:44
  • \$\begingroup\$ 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. \$\endgroup\$
    – Jernej
    Jun 6, 2011 at 15:03
  • \$\begingroup\$ exactly my point. \$\endgroup\$
    – Ali1S232
    Jun 6, 2011 at 15:08

1 Answer 1


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.

  • \$\begingroup\$ 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. \$\endgroup\$
    – Green_qaue
    Sep 29, 2012 at 14:30
  • \$\begingroup\$ @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. \$\endgroup\$
    – Ali1S232
    Sep 29, 2012 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .