Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the maximum size for an Android shared preference value?

I fully appreciate dumping lots of data into the preferences is totally inappropriate, but my requirement is not that great, but large enough (potentially 500-5000 bytes) where I've no idea whether it's appropriate or not. The docs do not help. http://developer.android.com/reference/android/content/SharedPreferences.Editor.html

I've searched the net and Stackoverflow and can't find a definitive answer on: a) what the actual limit is, based on the underlying architecture b) what the practical limit is, based on performance (I find writing even short pref values can take a few seconds, but I suspect that's just a flash write delay)

Would appreciate clarification.

like image 690
Ollie C Avatar asked Feb 07 '11 18:02

Ollie C


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).

What is Android shared preference?

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.

Can we use SharedPreferences in Android?

Android App Development for BeginnersShared 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.

Can an app have multiple shared pref files?

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


1 Answers

All shared prefs are stored in /data/data/[package name]/shared_prefs/[app name].xml, so i think there's no limit based on architecture.

I don't know practical limit but I think it's enough for you.

like image 168
merrymenvn Avatar answered Sep 19 '22 13:09

merrymenvn