Data Cache in General Preferences

I have 2 processes in my application. From one process, I save the data in SharedPreferences . From the second process - to receive. When I get data, I get SharedPreferences with old data (I check the xml file and see that currently the data in the file and the data that was received are different). It looks like this data has been cached. I changed the save methods (commit / apply), but not the result. PS: just 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); ...} 
+6
source share
1 answer

The solution adds the Context.MODE_MULTI_PROCESS flag to optional flags when opening shared preferences (available in API level 11 and above)

+17
source

Source: https://habr.com/ru/post/904995/


All Articles