How should I store a Game Database on Android?

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?

• Did you have a look at the Android Dev Guide on Data Storage? – Eric Jun 19 '12 at 15:33
• 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? – 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.

• Well, you can even technically use XPath to run "select" queries. +1, this is a good simple approach. – ashes999 Jun 19 '12 at 16:18
• +1 for the simple approach. I'll try this and see how it works out. Thanks! – 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.