Saving player data and status

时间秒杀一切 提交于 2020-01-24 19:31:11

问题


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?


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/5606152/saving-player-data-and-status

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!