How to edit data that has already been saved in SharedPreferences

2

Hello,

I'm making an application and I'm saving some information in SharedPreferences, which are user information, such as name / phone.

I'm doing an edit profile and wanted to know how do I change not only in the database (as I already did) but also in sharedPreferences.

How do I change data that has already been saved in shared preferences?

    
asked by anonymous 14.09.2018 / 13:48

1 answer

1

Just as you write, you can just overwrite your current preferences with the new value, you can refer to this page for more information.

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.saved_high_score_key), newHighScore);
editor.commit();
    
14.09.2018 / 14:05