• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Shared Preference Editor is taking a long time to update the value


Sep 12, 2023

Shared Preference Editor is taking a long time to update the value​

Shared Preference Editor is taking a long time (3-4 seconds) to update the value into the XML file.
Below is my scenario
  1. I am updating the parameter value into the shared pref.XML file.
  2. After updating the value withing 2-3 seconds I reboot the device.
  3. 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.
  4. 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?


We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.