I'm working on a game for Android and had been trying to figure out how to go about saving the values to external storage and reading them back later. I was going to go about outputting all the variables into a string, writing that to a file, then reading it back in later and hoping I can manage to parse it all back out into the right spots. Instead of that though, can I just take a snapshot of the state of the entire application (I assume like how the OS does when creating a bundle that it loads up on resume) and then put it on external storage for later loading? Mostly I'm asking if I am on the right track with how I want to go about this so I don't waste time reading up on that functionality. Any links to more info would be helpful as my own searching isn't turning up much. Probably because I'm not using the right terms at the moment.
Asked
Active
Viewed 60 times
0
-
One thing I did once was using google's GSON library I would juste encode my objects in JSON format and save them in a .json file.. It makes it really easy to parse objects! When you want them back, you retrieve the file, read it, dump the string in the parser and it returns an object or a list of objects. – Tascalator May 16 '14 at 19:04
-
https://code.google.com/p/google-gson/ – Tascalator May 16 '14 at 19:05
-
What kind of values are you saving off? Usually, you just want to use [`SharedPreferences`](http://developer.android.com/reference/android/content/SharedPreferences.html) to persist things. – ashishduh May 16 '14 at 19:13
-
The idea of the game is to create a civilization so there's a whole buttload of various doubles representing population, various amounts of resources, etc. Plus a few string values and a couple sections where there's data that needs to be kept together Deity name (string), deity type (double), devotion (double) but there may be more than one deity listed here and a section with "wonders" so it'd be Wonder name (string), type (double) but again there may be more than one. – EMacKuin May 16 '14 at 23:50
-
Looking at that GSon link, that might be how I need to do it. I'll read more and thank you. Mainly what I need here is a direction to start off in so that I know where to start reading. =) I am more than willing to do the work myself but I prefer to not go in completely blind. – EMacKuin May 16 '14 at 23:52