My situation is:
I have my settings fragment. Inside my settings fragment I can change language and theme. The question is: how can i save the user settings preferences even after the user closes the application, and once the user will reopen the app, he will have the options choosed before.
Could you give me some examples? Thanks
CodePudding user response:
get the sharedPreferences of the app in a fragment
mSharedPreferences = requireActivity().getSharedPreferences("createAKey" , Context.MODE_PRIVATE)
how to get a saved sharedPreference, the second parameter is like a else if you dont have saved before
var email = mSharedPreferences.getString("email_key" , "")
this is how you save a sharedPreference
mSharedPreferences.edit {
val email = "[email protected]"
putString("email_key" , email)
}
}