共享preferences"限制"preferences、QUOT

2023-09-07 11:19:51 作者:淡定、情緒

我知道类似的问题,这一个已经被问了无数次,和冲浪经历了那么我部分找到了答案,但不完全,而Android文档不真正的帮助。很明显,我知道他们是如何工作和以前很多次都使用的共享preferences,但我想知道在什么时候(多少)实在是太多了,我读过的人有保存没有任何问题〜100KBS。长话短说 - 是不是有人竟然出现了问题,存储在共享preferences太多的数据,什么是问题,没有数据被删除或?

I know similar question to this one has been asked a numerous times, and surfing through SO I partially found an answer, but not complete, and android docs don't really help. Obviously I know how they work and have used shared preferences many times before, but I am wondering at what point ( how many ) is too much, I've read people had ~ 100KBS stored without any problem. Long story short -- Did someone actually had problems with too many data stored in shared preferences and what was problem, does data get deleted or?

**这只是一个问题,出于好奇,我已经有存储在SQL数据库我大的数值,只是不知道会是什么,如果有哪个问题,如果有人在共享preferences某种原因存储一切

** this is only a question out of curiosity, I already have my large values stored in SQL DB, just wondered what would be and if there would be any problems if someone for some reason stored everything in shared preferences

推荐答案

由于共享preferences 保存在一个XML文件,因此缺乏强大的事务处理支持SQLite的,我不会建议在共享preferences

Since SharedPreferences are stored in an XML file, and therefore lacks the strong transaction support of SQLite, I would not recommend storing "100KBS" in SharedPreferences.

这就是说,最低的大小限制,我知道会是你的自由的堆空间量,因为共享preferences 读取整个XML文件的内容到存储器中。

That being said, the lowest size limit that I am aware of will be your amount of free heap space, as SharedPreferences reads that entire XML file's contents into memory.