getting the null value even though the syntax completely matches the online examples
                  
                  
                  
                  
                  
                  static SharedPreferences getPreferences(Context context) {
                  
                  
                      return context.getSharedPreferences(ACCOUNT_PREF_TAG, Context.MODE_PRIVATE);
                  
                  
                  }
                  
                  
                  
                  
                  
                  static SharedPreferences.Editor getPreferencesEditor(Context context) {
                  
                  
                      return getPreferences(context).edit();
                  
                  
                  }
                  
                  
                  
                  
                  
                  public static void setLoggedIn(Context context, boolean bool) {
                  
                  
                      getPreferencesEditor(context).putBoolean(IS_LOGGED_IN, bool);
                  
                  
                      getPreferencesEditor(context).commit();
                  
                  
                  }
                  
                  
                  
                  
                  
                  public static boolean getLoggedIn(Context context) {
                  
                  
                      return getPreferences(context).getBoolean(IS_LOGGED_IN, false);
                  
                  
                  }
                  
                  
                  This is how I'm setting and getting preference values. Is there anything wrong in my code?
                  
                  
                
try using this: https://github.com/Pixplicity/EasyPrefs
Are you sure context is not null?
I usually did this, before using that lib: Editor e = getPreferencesEditor(context); e.putBoolean(IS_LOGGED_IN, bool); e.commit();
When you are putting a boolean you should call .commit() on the same instance of editor, but you're creating a new one
Обсуждают сегодня