1

my question is how much data does Shared Preference take from device? I'm aware Shared Preference is used for small bits of data such as ints, strings etc but how much data does an int take from the device when stored in Shared Preferences? Thanks

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
DroidGalaxy
  • 109
  • 11

2 Answers2

2

I'm aware Shared Preference is used for small bits of data such as ints, strings etc but how much data does an int take from the device when stored in Shared Preferences

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. Also the whole XML file is read into memory so if you grow it too much (but rather MB than KBs) then you may face OutOfMemory on some devices with smaller heap.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • but if i want to store ints, would that create a problem? arent they extremely small in data? – DroidGalaxy Sep 26 '16 at 20:05
  • It's fine to store what you want. The point is to NOT use shared preferences instead of database. If you want to store 100 ints - it's perfectly fine. But if you need 10000, then maybe it'd be worth checking if that affects your app performance and memory usage and use SQLite instead – Marcin Orlowski Sep 27 '16 at 07:12
  • If I want to save more than 10 ints, would I have to create different Shared Preference for each int? (on the same activity). – DroidGalaxy Sep 27 '16 at 13:55
  • Of course not. I think that you got wrong imagination of what shared preferences is but from what you say you got just normal use patterns there so as long as you are i.e not going to put images or 10000 values there then you will be fine. – Marcin Orlowski Sep 27 '16 at 17:27
-1

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

Community
  • 1
  • 1