Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared Preferences - max length of a single value

I am storing String into shared preferences, but I wasn't able to find out maximal length of string I can store. Do you know this value?

like image 942
Waypoint Avatar asked Dec 15 '11 07:12

Waypoint


People also ask

How much data can shared preferences hold?

There's no hard limit. The main reason it is not recommended to use SharedPreferences in place of the database is mainly the performance -> shared preferences data is keept in ordinary flat XML file which lacks all the features SQLite offers.

Is shared preferences persistent?

Shared preferences is an Android class that allows apps to store key-value pairs of primitive data types. Once saved, information in shared preferences will persist across sessions.

How many SharedPreferences Can an app have?

You can have multiple SharedPreference files. So nothing wrong with the approach.

What is the 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.


2 Answers

By Romain Guy From the Question Asked Here,

Whatever the maximum length of a Java string is. So something like Integer.MAX_VALUE chars.

I suppose while SharedPreference is an XML file stored with One Tag if you store only One Pair/Object. So there is no limit to write String in that if you think like you are writing in a file..(Theoretically)

But Actually what happens is that, while you are assigning value to SharedPreference using put/get function at that time you Reading/Writting value in String Object..so the limit becomes to store value at one time equal to Size limit of String Object of Java.

So while writting the code: Limit of SharedPreference String Size = Java String Object Size Limit(Practically)

like image 106
MKJParekh Avatar answered Sep 24 '22 06:09

MKJParekh


Shared preference is stored in /data/data/[package_name]/shared_prefs/[app name].xml, I think there's no limit as per android architecture.

like image 43
Sunil Kumar Sahoo Avatar answered Sep 23 '22 06:09

Sunil Kumar Sahoo