Reputation: 6591
hi i have using shared preference for saving user name and password ,but when my application crashes i lost my data,i need to re login again(Only some crashes i lost the data ),how can i solve this problem ?
SharedData.userInfo = PreferenceManager .getDefaultSharedPreferences(ctx); SharedData.userAdd = SharedData.userInfo.edit(); SharedData.userAdd.putString("userEmailAddress", uname); SharedData.userAdd.putString("userPassword", upassword); SharedData.userAdd.commit();
Upvotes: 0
Views: 136
Reputation: 11251
I use it like this:
SharedPreferences sharedPref = getSharedPreferences("MyData",MODE_PRIVATE);
SharedPreferences.Editor prefEdit = sharedPref.edit();
prefEdit.putString("VariableName","Value");
prefEdit.commit();
and it works for me always.
Upvotes: 2