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?
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.
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.
You can have multiple SharedPreference files. So nothing wrong with the approach.
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.
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)
Shared preference is stored in /data/data/[package_name]/shared_prefs/[app name].xml
, I think there's no limit as per android architecture.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With