I am trying to save some String data using SharedPreference
.
Here is my code
// SAVE
SharedPreference mySharedPref = new SharedPreference("Data", 0);
mySharedPref.edit().putString("hello", "world");
mySharedPref.edit().putString("my", "code");
mySharedPref.edit().commit();
// LOAD
String str = mySharedPref.getString("hello", ""); // I expect "world"
But it only has an empty string!
Meanwhile,
SharedPreference.Editor editor = mySharedPref.edit();
editor.putString(...);
editor.commit();
This worked....
I thought mySharedPref.edit()
returns a reference and makes the code above and below the same.
I am confused now. X(