Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

How will I add a save game feature. Please help!

I have finished building my own version of the interactive story game in android. And I am on the verge of publishing it, but I would like to know how would I add a save game feature to it.

2 Answers

Beatriz Fuentes
Beatriz Fuentes
2,207 Points

Well , i think you should declare some Constant Varialbles probably Integer to keep track of user state, once done , you should save that variable into a sharedprefrences object (please try google to have a better understanding of permanent data storage in android ) the next step is to retrive the variable value when user reopen the app .

in short : declare , save , on restart check

Let's make it easy. A lot of games just have you restart the zone you were in when you quit. So now you just need zone info and player stats. You should write these to disk fairly often. There phone might dies. They might get mad and just turn it off. You get the idea. When the games starts up, initialize everything before they can play. You might have bugs you did not know about. It should be an easy process unless you have specific game events that only happen to a player once, then you need those recorded :D

If they turn of the game properly, it should be extremely easy to stop the game loop and record as needed.