I have 2 processes in my application. From one process i save data in to SharedPreferences
.
From second process - retrieve. When i retrieve data, i receive SharedPreferences
with old data(i check xml file and see, that currently data in file and data that was received are different). It looks like this data was cached. I changed saving methods (commit/apply) but no result.
PS: just for example 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);
...}
Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment. getDataDirectory() .
Clearing an app's cache does not clear the settings. The settings data (including shared preferences) is stored in a different place than the app's cache. You need to "clear data" to clear out the shared preferences.
Android's SharedPreferences class is used in many sample apps to store small amounts of non-relational data, and avoids doing extra disk I/O with an in-memory cache. You should not use it, for a whole host of reasons: Synchronous API encourages StrictMode violations.
There is no limit (except for storage space), but these are currently written as a single XML file for the entire shared preference object, so you don't want to go crazy with how much you put there. If you have a large amount of data there are numerous other facilities: databases, flat files, etc.
The solution is add to neccesary flags Context.MODE_MULTI_PROCESS flag when open shared preference (Available in API Level 11 and up)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With