Search code examples
androidgenericssetsharedpreferencesandroid-sharedpreferences

SharedPreferences takes not List but Set


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?


Solution

  • 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)