Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Value can't be saved when put value after clear() and kill app in background. #106

Open
IBeiBei opened this issue Dec 19, 2019 · 1 comment

Comments

@IBeiBei
Copy link

IBeiBei commented Dec 19, 2019

Demo project - MainActivity:
@debuglog
public void onGetButtonClick(View v) {
final String value = getSharedPref().getString(MainActivity.KEY, null);
toast(MainActivity.KEY + "'s, value= " + value);
}
@debuglog
public void onSetButtonClick(View v) {
getSharedPref().edit().clear().commit();// Add this line
getSharedPref().edit().putString(MainActivity.KEY, MainActivity.VALUE)
.commit();
toast(MainActivity.KEY + " with enc value:" + MainActivity.VALUE
+ ". Saved");
}
Then Kill app and relaunch, Click 'GET FOO' value =null. value should be 'Bar'.

@wiztensai
Copy link

in my case, it work if your sintax like this:
getSharedPref().edit(true, { clear() })

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants