I'm developing a game that is played by stages. Now here is the flow of the xml Start > List of stages. when I press start button I will be directed to stages page that has 5 buttons named stage 1 to stage 5 but the button stage 2 to stage 5 is disabled at the moment. It will be enabled if the user finished stage 1. What I want to do is if I unlocked stage 2 then I terminate the app, when I opened it again after I press start button I want to see that the stage 2 is unlocked already. How can I do that? what is happening is when I terminate then launch again after I press start button, the last stage I finished is still unlocked. in every stage the user unlocked should be saved so that if the game is closed using back button or home key, the last stage unlocked by the user still saved.
Asked
Active
Viewed 182 times
1 Answers
1
You can save game progress (stages) using SharedPreferences: http://developer.android.com/guide/topics/data/data-storage.html#pref . You can save progress every time user passes to the next level or inside onPause
method (then progress will be saved only when user leaves your application). Inside your onCreate
method you can retrieve this values and start the game with proper progress.

XorOrNor
- 8,868
- 12
- 48
- 81
-
sir can you give me some sample code? i'm having a hard time studying about sharedprefs and sqlite. i'm just a student beginner in android. – Jerome Feb 04 '13 at 19:09
-
Hope that this thread will be usefull for you: http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values – XorOrNor Feb 04 '13 at 19:18
-
How can I do it inside the onClick? for example in my game, whenever the user press start button he will directed to list of stages in which stage1 is the only enabled button. when he finished stage1, stage2 will unlocked, when he exits the game then press start again, he will be directed to list of stages in which stage 1 and stage 2 is already unlocked? – Jerome Feb 04 '13 at 19:35