- Trouble with SharedPreferences conflicting during app operation and then disappearing entirely after an app force close/reboot of device
- 07-22 13:28:13.980: W/SharedPreferencesImpl(7905):org.xmlpull.v1.XmlPullParserException: Map value without name attribute: string
- and
- 07-22 13:28:13.980: W/SharedPreferencesImpl(7905): at android.app.SharedPreferencesImpl.loadFromDiskLocked(SharedPreferencesImpl.java:113)
- public class SharedPrefs
- {
- public static String PREF_FILE = "HangedRes";
- public static String USERSCORE;
- public static String EXTRAWORDS;
- /////////////////////////////////////////////////////////////////
- static SharedPreferences settings;
- static SharedPreferences.Editor editor;
- ///////////////////////////////////////////////////////////////////
- public static String getStringPreference(Context context, String key)
- {
- settings = context.getSharedPreferences(PREF_FILE, Context.MODE_WORLD_READABLE);
- editor = settings.edit();
- String result = settings.getString(key, null);
- return result;
- }
- public static void setStringPreference(Context context, String key, String value)
- {
- settings = context.getSharedPreferences(PREF_FILE, Context.MODE_WORLD_READABLE);
- editor = settings.edit();
- editor.putString(key, value);
- //editor.apply();
- editor.commit();
- }
- /*
- public static boolean getBooleanPreference(Context context, String key) {
- settings = context.getSharedPreferences(PREF_FILE, 0);
- editor = settings.edit();
- boolean result = settings.getBoolean(key, false);
- return result;
- }
- public static void setBooleanPreference(Context context, String key, boolean value)
- {
- settings = context.getSharedPreferences(PREF_FILE, 0);
- editor = settings.edit();
- editor.putBoolean(key, value);
- editor.commit();
- }
- */
- }
- // Get current user points and display //////////////////////////
- userScore = SharedPrefs.getStringPreference(this, SharedPrefs.USERSCORE);
- //Check if things are unlocked
- ownWords = SharedPrefs.getStringPreference(this, SharedPrefs.EXTRAWORDS);
- public static String USERSCORE;
- public static String EXTRAWORDS;
- public static String USERSCORE="USERSCORE";
- public static String EXTRAWORDS="EXTRAWORDS";`