我做了一个 android 游戏,我想知道如何保存玩家数据,例如金钱、达到的等级等。我认为 XML 并不是一种真正方便的方法。有什么好办法吗? android有没有提供一些方法来保存数据?
最佳答案
对于您需要跟踪的数据类型,数据库可能有点过分了。我建议使用 Android 的 SharedPreferences API。 See here for a tutorial .
这是一个 official overview of Android data persistence方法包括 SharedPreferences 和 SQLite。
查看 getStringSet用于存储数组/集合的 API。
对于字符串集不存在的值:
Returns the preference values if they exist, or defValues. Throws ClassCastException if there is a preference with this name that is not a Set.
对于不存在的值数据,如string、bool、float等:
Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not a String.
关于android - 保存播放器数据和状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5606152/