Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared Preferences "limit"

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?

** 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

like image 306
Marko Niciforovic Avatar asked Mar 25 '13 14:03

Marko Niciforovic


People also ask

How much data can I store in shared preferences?

SharedPreferences are not intended to store a lot of data, there is no limit per se (since it is an xml file), but for larger sets of data, I would suggest using Room (or SQLite for the older projects).

Can an app have multiple shared pref files?

Yes you can maintain as many shared preference files for an app as you can.

What are shared preferences and how do you use it?

Shared Preferences allow you to save and retrieve data in the form of key,value pair. In order to use shared preferences, you have to call a method getSharedPreferences() that returns a SharedPreference instance pointing to the file that contains the values of preferences.

What is meant by shared preferences?

A SharedPreferences object points to a file containing key-value pairs and provides simple methods to read and write them. Each SharedPreferences file is managed by the framework and can be private or shared. This page shows you how to use the SharedPreferences APIs to store and retrieve simple values.


1 Answers

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.

like image 164
CommonsWare Avatar answered Sep 20 '22 04:09

CommonsWare