0

I need to pass an ArrayList across activities and make it persistent. From a popular SO post i found the solution. But still I cannot understand why SharedPreference from API 11 takes a Set SharedPredferences.getStringSet but not a so common ArrayList directly. What are the logic reasons, ex. as to avoid duplicates using a Set for instance?

Community
  • 1
  • 1
trocchietto
  • 2,607
  • 2
  • 23
  • 36

2 Answers2

1

With reference of this, Concept behind SharedPreference is build a user interface for your app settings. you can only add key-value type of data in shared preference.

Pranav P
  • 1,755
  • 19
  • 39
1

If you only need to persist simple flags and your application runs in a single process SharedPreferences is probably enough for you. It is a good default option.

There are two reasons why you might not want to use SharedPreferences:

  1. Performance: Your data is complex or there is a lot of it
  2. Multiple processes accessing the data: You have widgets or remote services that run in their own processes and require synchronized data

You should can use Bundle to share list to another activities. If it is a globally used stuff keep it in your Database(Sqlite)

LvN
  • 701
  • 1
  • 6
  • 22
  • your reply is much more pragmatic, it avoids the problem of using ArrayList, so although Pranav showed more clearly that structurally SharedPreference is made to take k, values, you went down directly on the performance reasons and suggested 2 solutions. One of them the SQlite is the one I am going to use, as I discovered can use DISTINCT to retrieve unique values in the column where I have the ArrayList values! – trocchietto Jul 29 '16 at 12:12