I'm looking at creating a game for Android and while I have most of the ins and outs worked out, the one thing I'm struggling with is how to store data for the game.

Ultimately, the game will be based off of a lot of pre-defined data and statistics so the obvious choice to me would be something like SQLite, but as I'm pretty new to the realm of Android and Game Development, I'm not 100% certain if this is the right route to follow.

The data will be general pre-defined data as well as player data (along the lines of careers stats - what place finished, etc).

I was wondering if there was a better/best practice solution that wasn't SQLite and that would provide said functionality and if so, could you point me in the right direction?

  • \$\begingroup\$ Did you have a look at the Android Dev Guide on Data Storage? \$\endgroup\$ – Eric Jun 19 '12 at 15:33
  • \$\begingroup\$ I did, but I'm still uncertain which would be the best option for a game. Though it could just be the way I'm looking at it as all in all, it's just the same as any other app that's data driven, right? \$\endgroup\$ – LiamGu Jun 19 '12 at 17:00

I am just doing one which simply creates xml files. For example an entire level is saved as an xml file and then reloaded when needed, unless the user has finished the level, then a new random one is created. Every object is one tag with its attributes like

<Object name="car" color="blue" maxspeed="300" />

I think this is more simple way to do it when one does not need to do a lot read/write operations, i.e. does not actually need a fast database.

But for the smaller amount of data user preferences saved in the private application space can do.

  • \$\begingroup\$ Well, you can even technically use XPath to run "select" queries. +1, this is a good simple approach. \$\endgroup\$ – ashes999 Jun 19 '12 at 16:18
  • \$\begingroup\$ +1 for the simple approach. I'll try this and see how it works out. Thanks! \$\endgroup\$ – LiamGu Jun 19 '12 at 17:02

Embedding a SQLite database into your application isn't too hard. There are lots of examples on the web, such as http://www.vogella.com/articles/AndroidSQLite/article.html XML (as suggested by Lumis) or plain text file could also work. For an example of XML, see the following: https://stackoverflow.com/questions/10535472/android-development-where-to-put-static-key-value-pairs. For the flat text file, you could use a simple stringtokenizer to seperate your key/value pairs.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.