secure-preferences icon indicating copy to clipboard operation
secure-preferences copied to clipboard

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

Open IBeiBei opened this issue 5 years ago • 1 comments
trafficstars

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'.

IBeiBei avatar Dec 19 '19 09:12 IBeiBei

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

wiztensai avatar Feb 06 '20 17:02 wiztensai