What does Preference.setSummary () do?
In my code, I used a method Preference.setSummary()
to change the resulting parameter string to a specific string. In my main activity, when I need to get this parameter value, I call the method getString(key)
on the object SharedPreferences
where key
is the key EditTextPreference
.
Now I'm really wondering if setSummary
the preference value in SharedPreferences
the same key is added to the value I pass in setSummary
, because I never really created an object SharedPreferences.Editor
and called putString
on it explicitly.
The docs don't say anything specific other than:
Sets the summary for this preference using a CharSequence.
Parameters
summary Summary for preference.
source to share
First, I'm sorry I asked this question, although one of the following lectures on the course (from Google) gave the answer, but I think it was worth it, which there was no question about SO about Preference.setSummary()
storing values in SharedPreferences
.
The answer is that when the crash changes, so that's the value in SharedPreferences
, as pointed out in this video by the official Google Android course:
When the user selects an option, it is saved to SharedPreferences.
By providing some context, "user selects an option" refers to the selection of an option in ListPreference
, which is then set as a summary.
source to share