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.
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.
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
java.io package, and maybe the
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!).