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 made simple puzzle game. I want to add a "Resume" option to it, so when user opens the game, he can pick up where he left off last time.

share|improve this question

You'll have to write your current game-state to "disk" whenever the user quits the application or triggers a "save-game" manually. This is also called serialization. Whenever the application resumes, deserialize the data and restore the previous game-state.

The data that is needed for serialization heavily depends on your game.

I'm not an android developer, but I suggest you have a look at the Serializable Interface and the onPause and onResume callbacks.

share|improve this answer

There are several ways to preserve state in Android apps.

If your gameplay is limited to a single Activity (common for anything relying a SurfaceView), and your game state is relatively small, you can often rely on the savedInstanceState Bundle passed into Activity.onCreate. Not only does this allow to to support saved state as the user goes into and out of the game, it will also bullet proof your code against various Configuration changes, such as opening the keyboard or changing display mode.

You can also use SharedPreferences to store data in one or more key/value maps. This is probably the most common solution, and becomes available to all Activities within your app (and even other entry points, such as BroadcastReceivers, in a thread safe manner.

Probably not the best approach for games, other than some deep inventory RPGS, every Android device has an SQL instance built in.

Finally, you have access to the file system. Both in an application private folder accessible by Context.getDir(..), or via the phone's SD Card. The latter will require an additional user privledge, but it is the best route to go if you expect your game state to be large (half a meg or more). Both will require you to get familiar with the package, and maybe the java.nio package.

If you want state to persist between reinstalls, you'll have to look at setting up backup support for your app, or run a server that can store and retrieve state. I've had good luck with using Google App Engine for network server (for free!).

share|improve this answer

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.