Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 2.17 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Trouble with SharedPreferences conflicting during app operation and then disappearing entirely after an app force close/reboot of device
  2. 07-22 13:28:13.980: W/SharedPreferencesImpl(7905):org.xmlpull.v1.XmlPullParserException: Map value without name attribute: string
  3. and
  4. 07-22 13:28:13.980: W/SharedPreferencesImpl(7905):  at android.app.SharedPreferencesImpl.loadFromDiskLocked(SharedPreferencesImpl.java:113)
  5.        
  6. public class SharedPrefs
  7. {
  8. public static String PREF_FILE = "HangedRes";
  9. public static String USERSCORE;
  10. public static String EXTRAWORDS;
  11.  
  12. /////////////////////////////////////////////////////////////////
  13.  
  14. static SharedPreferences settings;
  15. static SharedPreferences.Editor editor;
  16.  
  17. ///////////////////////////////////////////////////////////////////
  18.  
  19. public static String getStringPreference(Context context, String key)
  20. {
  21.     settings = context.getSharedPreferences(PREF_FILE, Context.MODE_WORLD_READABLE);
  22.  
  23.     editor = settings.edit();
  24.  
  25.     String result = settings.getString(key, null);
  26.  
  27.     return result;
  28. }
  29.  
  30. public static void setStringPreference(Context context, String key, String value)
  31. {
  32.     settings = context.getSharedPreferences(PREF_FILE, Context.MODE_WORLD_READABLE);
  33.     editor = settings.edit();
  34.     editor.putString(key, value);
  35.     //editor.apply();
  36.     editor.commit();
  37. }
  38.  
  39. /*
  40. public static boolean getBooleanPreference(Context context, String key) {
  41.     settings = context.getSharedPreferences(PREF_FILE, 0);
  42.     editor = settings.edit();
  43.  
  44.     boolean result = settings.getBoolean(key, false);
  45.     return result;
  46. }
  47.  
  48. public static void setBooleanPreference(Context context, String key, boolean value)
  49. {
  50.     settings = context.getSharedPreferences(PREF_FILE, 0);
  51.     editor = settings.edit();
  52.  
  53.     editor.putBoolean(key, value);
  54.     editor.commit();
  55. }
  56. */
  57.  
  58.  
  59. }
  60.        
  61. // Get current user points and display //////////////////////////
  62.     userScore = SharedPrefs.getStringPreference(this, SharedPrefs.USERSCORE);
  63.  
  64.     //Check if things are unlocked
  65.     ownWords = SharedPrefs.getStringPreference(this, SharedPrefs.EXTRAWORDS);
  66.        
  67. public static String USERSCORE;
  68. public static String EXTRAWORDS;
  69.        
  70. public static String USERSCORE="USERSCORE";
  71. public static String EXTRAWORDS="EXTRAWORDS";`