Storing a String array in the SharedPreferences

后端 未结 3 1613
盖世英雄少女心
盖世英雄少女心 2020-12-28 21:52

I was wondering if it could be possible to save in the shared preferences an array of Strings, in a way that, every time we save a certain String, we store it in that array.

3条回答
  •  情书的邮戳
    2020-12-28 22:39

    This is doable: I was just blogging about it:

    SAVE YOUR ARRAY

    //String array[]
    //SharedPreferences prefs
    Editor edit = prefs.edit();
    edit.putInt("array_size", array.length);
    for(int i=0;i

    RETRIEVE YOUR ARRAY

    int size = prefs.getInt("array_size", 0);
    array = new String[size];
    for(int i=0; i

    Just wrote that so there might be typos.

提交回复
热议问题