3

In my code I've used the Preference.setSummary() method to change the summary line of a setting to a certain string. In my main activity when I need to retrieve this setting's value I call the getString(key) method on the SharedPreferences object, where key is the key of an EditTextPreference.

Now I really wonder if setSummary also sets the value of a preference in SharedPreferences by the same key to the value that I pass to setSummary, because I really never created a SharedPreferences.Editor object and called a putString method on it explicitly.

The docs don't say anything specific other than:

Sets the summary for this Preference with a CharSequence.

Parameters

summary The summary for the preference.

Reference

Anshu Dwibhashi
  • 4,617
  • 3
  • 28
  • 59

1 Answers1

7

Firstly I'm sorry that I asked this question even though one of the next lectures in the course (by Google) provided the answer, but I think it was worth it as there existed no question on SO about Preference.setSummary() also saving values in SharedPreferences.

The answer is that when the summary is changed so is the value in SharedPreferences as quoted in this video by Google's official Android Course:

When the user selects an option, it's saved into SharedPreferences.

Providing some context, "user selects an option" refers to choosing an option in a ListPreference which is then set as its summary.

Anshu Dwibhashi
  • 4,617
  • 3
  • 28
  • 59