Save arraylist with sharedpreference

0

hi I am with a problem I have an arraylist that has strings in and I want to keep them with sharedpreference the theme is that I can not keep a arraylist then reading by there lei how to do it by transforming the arraylist in a hashset I did it keep the preferences the problem comes when I want to restore that take the preference to transform it from hashset to the return list

public void guardarpreferencias() {
        SharedPreferences preferences = getSharedPreferences("lista", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        Set<String> set = new HashSet<>();
        set.addAll(list);
        editor.putStringSet("datos", set);
    }

    public void cargarpreferencias() {

        SharedPreferences preferences = getSharedPreferences("lista", Context.MODE_PRIVATE);
        Set<String> set = preferences.getStringSet("datos", null);
        list.addAll(set);
    }

is loading the preferences what slows me down the application some solution? because if I do not call you, it does not slow down.

I also saw that the transformation is done with Gson that I do not know what it is but he does not let me use it anyway.

    
asked by Houth 22.05.2018 в 03:17
source

1 answer

0

You need to do commit() when you save, you should stay

editor.putStringSet("datos", set).commit();
    
answered by 22.05.2018 в 05:13