How to edit data that has already been saved in Sharedpreferences

Asked

Viewed 77 times

2

Hello,

I’m making an app and I’m saving some information in Sharedpreferences, which is user information, such as name/phone.

I’m editing a profile and wanted to know how to 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?

1 answer

1


In the same way that 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();
  • 1

    I understood, I used a key to save the preferences, so I just reused this key and apparently it overwrites. Thanks anyway!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.