This is in my onCreate:
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
sharedPrefs being an uninitialized SharedPreferences in the class.
Later, I do this:
sharedPrefs.edit().putString("token", token);
Log.d("asdf", "token is " + token);
Log.d("asdf", "reading prefs: " + sharedPrefs.getString("token", null));
And the log output is as follows:
token is ABC123
reading prefs: null
So token (a string) is definitely getting set correctly. But for some reason.. it just won’t save/read in the sharedPreferences.
Any ideas? I’ll post the full code if you guys want, but I doubt it’ll help.
After the
put()method, you should implementsharedPrefs.edit().commit()to commit the data into the sharedpreference.