Shared Preference Editor is taking a long time (3-4 seconds) to update the value into the XML file.
Below is my scenario
- I am updating the parameter value into the shared pref.XML file.
- After updating the value withing 2-3 seconds I reboot the device.
- After reboot I am able to see there is two shared pref XML file in /data/data/apk.package/shared_pref path. one is original and another one is xml.bak file In xml.bak file parameter value is not updated while in xml file value has been updated properly.
- After reboot when I run the application, bak.xml is convert into the main xml file (main xml file deleted) and application read parameter value from bak.xml file which is not correct.
Below is my source code
sUserPref = app.getSharedPreferences("ABC", Context.MODE_PRIVATE);
sUserEditor = sUserPref.edit();
sUserEditor.putInt(storedKey, value);
if (sUserEditor.commit()) {
LogHelper.Logd(DBG_HEADER, "commit success");
return true;
} else {
return false;
}
Why sharedpref is taking time to update the file? Is it depends on the memory in the device? Is there any other alternative?
Top comments (0)