一、存储方法
private final String SAVE_NAME= "test"; protected void onStop() { SharedPreferences mySharedPreferences = getSharedPreferences(
SharedPreferences.Editor editor = mySharedPreferences.edit();editor.clear();for (int i = 0; i < list.size(); i++) {editor.putInt("id" + i, list.get(i).getId());}editor.commit();super.onStop();}SAVE_NAME, Activity.MODE_PRIVATE);
二、读取方法
SharedPreferences myPreferences = getSharedPreferences(
Map<String, ?> mapIds = myPreferences.getAll();SAVE_NAME, Activity.MODE_PRIVATE);
还可以用getString(“key”,"默认值")方法。