简体   繁体   English

Android SharedPreferences 导致存储空间很大

[英]Android SharedPreferences causing storage to be big

i am using SharedPreferences in my app to save some String values at some point.我在我的应用程序中使用 SharedPreferences 在某个时候保存一些字符串值。 but the problem is after running the app a couple of time, there will be about 100MB of data on user's phone and this data keep getting bigger and bigger.但问题是在运行应用程序几次后,用户手机上会有大约 100MB 的数据,并且这些数据越来越大。 and ofcource i am replacing new data with old data on sharedPreferences what should i do?并且ofcource我正在用sharedPreferences上的旧数据替换新数据我该怎么办? should i use Database instead?我应该改用数据库吗?

From Android Docs: https://developer.android.com/training/data-storage/shared-preferences来自 Android 文档: https://developer.android.com/training/data-storage/shared-preferences

If you have a relatively small collection of key-values that you'd like to save, you should use the SharedPreferences APIs.如果您想要保存的键值集合相对较少,则应使用 SharedPreferences API。 A SharedPreferences object points to a file containing key-value pairs and provides simple methods to read and write them. SharedPreferences object 指向包含键值对的文件,并提供读取和写入它们的简单方法。

Use shared preferences for small key value pairs, eg Storing a user id or some setting variable based on which the app experience would be defined further.对小键值对使用共享首选项,例如存储用户 id 或一些设置变量,基于这些变量将进一步定义应用程序体验。

Your options are SQLite or Room (SQLite Wrapper) databases, if data is expected to grow so much (GBs or more), go with remote storage with either Firebase or privately owned server database您的选择是 SQLite 或 Room (SQLite Wrapper) 数据库,如果预计数据会增长这么多(GB 或更多),go 具有远程存储与 Z035489FF8D092741943E4A83241F5 数据库或私有数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM