secure-preferences
secure-preferences copied to clipboard
Value can't be saved when put value after clear() and kill app in background.
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'.
in my case, it work if your sintax like this:
getSharedPref().edit(true, { clear() })