Shared Preferences reset data when app crashed. Please guide Shared Preferences reset data when app crashed. Please guide sqlite sqlite

Shared Preferences reset data when app crashed. Please guide


So after the crash when it went to load the Preferences there was a blank in the preferences xml file which caused the preferences to reset.

To avoid this you could put all preference modifications in synchronized blocks or even use one synchronized static method for all preference writing.

I think - you need a better way of managing and storing the data you're saving.

The next time the shared preferences were accessed however, the xml file was cleared and started new.

for example :

private static final class SharedPreferencesImpl implements SharedPreferences {...    public String getString(String key, String defValue) {        synchronized (this) {            String v = (String)mMap.get(key);            return v != null ? v : defValue;        }   }...    public final class EditorImpl implements Editor {        public Editor putString(String key, String value) {            synchronized (this) {                mModified.put(key, value);                return this;            }        }    ...    }}