tags:

views:

17

answers:

2

I have an unlockable mode in my game that is only available once the story mode has been completed. This works perfectly if the story mode is completed during a test play through, because upon returning to the main menu the bonus mode is unlocked and selectable. However when I shut down the app and relaunch it, none of the previous state information is retained and it requires you to beat the story mode again to access the bonus mode.

I use the onSaveInstanceState method to create a bundle that stores this information (ie. a boolean whether the mode is unlocked or not), but this information seems to be lost between ending the app, and relaunching it. The onCreate method takes the parameter of a savedInstanceState but yet this seems to be null.

Is there a step that I'm missing out, or doing incorrectly somewhere along the line? On a PC game I would just serialize the state into a text file and look for a special string/symbol upon initialization but I cant do that here so i thought the outState bundle you create in SIS was how you retained information for use upon next launching the app again?

A: 

Look up SharedPreferences. It's very easy to use, and will last you until the app is uninstalled. http://developer.android.com/reference/android/content/SharedPreferences.html

onSaveInstanceState is really just to retain the state while the app is recreated because of an orientation change or something similar.

EboMike
Thanks very much. That looks like exactly what I'm after
Greenhouse Gases
+1  A: 

Check out the following webpage it tells you the various way you can store data. Shared preference is what I would suggest in your case

http://developer.android.com/guide/topics/data/data-storage.html#preferences

josnidhin