Append more values to Shared Preferences rather than overwriting the existing values

前端 未结 3 1909
孤独总比滥情好
孤独总比滥情好 2021-01-20 23:27

In my app, I need the values to be saved in to Sharedpreferences file RKs_Data without overwriting the existing data. Every time, I click \'Yes\' in my app, I require all the va

3条回答
  •  我在风中等你
    2021-01-21 00:07

    Follow these steps:

    Extract the value stored in SharedPreferences

    String value = prefs.getString(, );
    

    Append to the extracted value

    String appendedValue = append(value, newValue);
    

    Write the result back to SharedPreferences

    editor.putString(, appendedValue).commit();
    

提交回复
热议问题