Reputation: 4480
I made an android game and I want to know how to save player data such as money, level reached, etc. I think that XML is not a really convenient way to do this. Is there any good way to do this? Does android provide some method to save the data?
Upvotes: 1
Views: 526
Reputation: 81489
A database is probably overkill for the type of data you need to track. I would suggest using Android's SharedPreferences APIs. See here for a tutorial.
Here's an official overview of Android data persistence methods including SharedPreferences and SQLite.
Check out the getStringSet API for storage of arrays/collections.
For non-existent vals for the string set:
Returns the preference values if they exist, or defValues. Throws ClassCastException if there is a preference with this name that is not a Set.
For non-existent value data such as string, bool, float etc.:
Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not a String.
Upvotes: 1
Reputation: 7696
Use a SQlite database. ( Data storage on developers.android )
Here is a tutorial that shows the functionality:
http://p-xr.com/android-tutorial-simple-but-persistent-data-storage/
Upvotes: 0