我的申请中有2个流程。从一个过程中,我将数据保存到SharedPreferences
中。
从第二个过程-检索。当我检索数据时,我收到带有旧数据的SharedPreferences
(我检查xml文件,然后看到文件中的当前数据与接收到的数据不同)。看来该数据已被缓存。我更改了保存方法(提交/应用),但没有结果。
PS:例如http://pastebin.com/Zx2ffvSg
//saving
{ ...
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
prefsEditor.putString(MY_NAME, "Sai");
prefsEditor.putString(MY_WALLPAPER, "f664.PNG");
prefsEditor.commit();
... }
//retrieving
// when i call getData() I put "this" as argument.
public void getData(Context context){
SharedPreferences myPrefs = context.getSharedPreferences("myPrefs", MODE_PRIVATE);
...}
最佳答案
解决方案是在打开共享首选项时添加到必要的标志Context.MODE_MULTI_PROCESS标志(在API级别11及更高版本中可用)
关于android - 共享首选项中的数据缓存,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8714793/