我的应用程序中有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);
...}
Run Code Online (Sandbox Code Playgroud) 描述:我有两个应用程序App1和App2.我正在使用App1在SharedPreferences中存储一些键值对.我在App2中访问相同的键值.
我启动了app1.创建值为abc的密钥.现在我将app1保留在后台并启动App2,然后将键值更改为def.
当我将app1从后台启动到前台并访问键值时.检索到的值是abc而不是更新的值def.如果我从后台杀死App2并重新启动它,那么只会更新更新的值