2021年4月5日星期一

Android SharedPreference value is getting cleared on app close

I am saving my UserId on SharedPreference for future use. But that data getting cleared if I close that app or kill the app.

code used to save:

 SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());      SharedPreferences.Editor editor = app_preferences.edit();      editor.clear();      editor.putString("USERID", valu1);      editor.apply();  

code to retrieve :

 SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());          userID = app_preferences.getString("USERID", "");         

Any suggestions?

https://stackoverflow.com/questions/66956650/android-sharedpreference-value-is-getting-cleared-on-app-close April 06, 2021 at 12:54AM

没有评论:

发表评论