2

I just want to ask if it is good practice to save large array lists (of custom objects) in the Shared preferences using Gson.

By large I mean that the list might contain up to 500 object.

  • 3
    SharedPreferences are stored as XML and are basically meant to store small amounts of data. You should use a db instead, like SQLite. Refer https://stackoverflow.com/questions/15617825/shared-preferences-limit – Anuraag Baishya Mar 01 '18 at 09:40
  • so you wouldn't recommend it to save lists in the shared preferences, is there any alternative to sqlite that spare me the time of creating tables and acceptes json objects like the shared prefs does immediately? – IntegratedDigitalSystems IDS Mar 01 '18 at 09:44
  • You could look at Realm: https://realm.io/docs/java/latest – Anuraag Baishya Mar 01 '18 at 09:47
  • Just put them in shared preferences. 500 entries is not much. If you put them in a database you will need the same storage space from internal private memory. You could also save them to a file of course. – greenapps Mar 01 '18 at 09:55

1 Answers1

3

As you can read in android reference docs: https://developer.android.com/training/data-storage/shared-preferences.html

If you have a relatively small collection of key-values that you'd like to save, you should use the SharedPreferences APIs.

Else if you have a large amount of data the best solution is to use file storage or sqlite or anything else.

Shared preference is made for store private primitive data types: booleans, floats, ints, longs, and strings, not arrays or complex objects.

danilonet
  • 1,757
  • 16
  • 33