Shared Preferences “limit”

前端 未结 3 1753
误落风尘
误落风尘 2020-11-27 20:01

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 hel

相关标签:
3条回答
  • 2020-11-27 20:25

    There is a limitations of SharedPreference data. In my case it throw a Memory Exception when SharedPreference data cross 1428.51-kb.

    So its better to use SQLite database when you required huge data to store.

    0 讨论(0)
  • 2020-11-27 20:45

    From reading your question I would think that you should not be using SharedPreferences, because (a) they are intended for storing much smaller amounts of data (hence the use of XML), and (b) there are many simple alternatives.

    The only thing 'special' about SharedPreferences is the integration with the Preferences Activity for showing your preferences to the user, and that is probably not applicable in your case based on the amount you plan to store. (Oh, also the SharePreferences handles concurrency issues for you.)

    You could use Java's serialization to store Preference class(s) in binary files. These would be dramatically smaller then comparable PreferenceFile and can easily be passed through GZIPInputStream to make it smaller (or CipherInputStream) to encrypt it. I have found this alternate to be a powerful, simple, and cross-platform way to store app data where the power of SQLite is not needed.

    (Sorry this isn't a direct answer.)

    0 讨论(0)
  • 2020-11-27 20:48

    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.

    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.

    0 讨论(0)
提交回复
热议问题