I used the method in ShredPreferences, this way I saved my app-settind, But I have a question. Is it possible to Reset my saved settings, and come back to default value? The code that I'm using saves the changes of ImageButton's image. I would like to reset settings and restore default value after a click of a specific Reset-Button.
Thanks for everything!
private static final String Mypref= "pref";
final SharedPreferences pref = getSharedPreferences(Mypref, Context.MODE_PRIVATE);
buttonClick1.setImageResource(pref.getInt(Mypref, R.drawable.default_value));
image.setImageResource(imageResource);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("Mypref", R.drawable.users_value_chosen);
editor.commit();
simply use clear() function with your variable it will clear all the shared preferences. SharedPreferences preferences = await SharedPreferences. getInstance(); await preferences. clear();
clear(), It delete only values (means that keys are available) or it delete key value pair. check the following code. SharedPreferences userlogindetails = getSharedPreferences("userdetails", MODE_PRIVATE); SharedPreferences.
I was storing a String value in SharedPreferences that was setting the value for a Dropdownmenu . Now I have updated those values so the previous are no longer valid. However, even after uninstalling the app and clearing the data the old shared preference value is still there.
You can simply remove (clear) shared preferences. Then, when you read them, just provide default values in the code.
pref.edit().clear().commit();
The next line will use R.drawable.default_value as a default value, because preferences were deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With