1.字义键值名PREF_HISTORY_LIST_STRING

private final String PREF_HISTORY_LIST_STRING = “pre_historyListString”;

2.保存键值对

SharedPreferences settings = getActivity().getPreferences(
                Activity.MODE_PRIVATE);

historyString=”保存的字符串”;

Editor editor = settings.edit();// 编辑器记录
editor.putString(PREF_HISTORY_LIST_STRING, historyString);
editor.commit();// 提交保存

3.读取键值对

SharedPreferences settings = getActivity().getPreferences(
                Activity.MODE_PRIVATE);

String historyString = settings.getString(PREF_HISTORY_LIST_STRING, “”);// 获得用户字串