Nazerke
Nazerke

Reputation: 2098

How to save settings of the game?

I'm developing simple android game with a menu and 3 stages of game. Currently I'm working on saving game state. In the menu activity user can change some settings such as audio(on/off), ads(on/off), etc. When the user presses "new game", therefore leaves menu activity for game activity:

1) Should I finish menu activity and restart it by intent every time user presses back button in the game? Keeping them both(menu activity and the game activity) alive gives OutOfMemory error.

2) Where I should save settings user changed in the menu?

Saving game state and android development is new to me, so I would appreciate detailed replies.

Upvotes: 0

Views: 837

Answers (3)

Basbous
Basbous

Reputation: 3925

Your data storage options are the following:

  1. Shared Preferences : Store private primitive data in key-value pairs.
  2. Internal Storage : Store private data on the device memory.
  3. External Storage : Store public data on the shared external storage.
  4. SQLite Databases : Store structured data in a private database.
  5. Network Connection : Store data on the web with your own network server.

source : developer.android.com

Upvotes: 1

Sietse van der Molen
Sietse van der Molen

Reputation: 705

One of the things Google is trying to push on game devs is their Google Play Game Services. You could solve your problem with it. If you don't want the added learning curve for that, you can save your settings using SharedPreferences. More information about storing data can be found here: data storage.

I highly recommend reading Google's Android developer documentation. A lot of questions are answered there.

Upvotes: 1

Hitman
Hitman

Reputation: 598

Using Preferences.

Here are some useful links that will help you doing this:

  1. Settings
  2. android.preference package
  3. Shared Preferences
  4. Shared Preferences.Editor
  5. Preference

Upvotes: 1

Related Questions