how to store and retrieve (key,value) kind of data using saved preferences android

后端 未结 5 1891
终归单人心
终归单人心 2021-01-06 18:10

I have a hash map table as below,

HashMap backUpCurency_values = new HashMap();

and i want to

5条回答
  •  长情又很酷
    2021-01-06 18:43

    You can use SharedPreference like this:

    SharedPreferences s_pref=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    Editor edit=s_pref.edit();
    
    edit.putString("key","value");
    edit.commit();
    

    later you can use it like:

    String s=s_pref.getString("key","default value");
    

    But,you must have list of keys you have saved values with,into SharedPreferences so that you can get values easily at the time of retrieving them.

提交回复
热议问题