Reputation: 8350
The Preference class has a method called getExtras().
It may or may be not related to the Preference intent, but the Extras can be get and put using the intent directly.
There is no method putExtra/s() in the Preference class, then...
what is the purpose of getExtras()? In which scenrarios is it used?
Upvotes: 0
Views: 821
Reputation: 155
To improve the topic. The getExtras()
is particularly useful for associating some data with preferences that are generated dynamically, for example a list of switch preferences. Then you attach the Preference.OnPreferenceClickListener#onPreferenceChange(Preference,Object)
and listen to them all. Once the state of preferences changes, you get their extras directly. Otherwise you had to maintain a HashMap
of preference keys for their corresponding payload data.
Upvotes: 0
Reputation: 11
It's not explained all that well in the documentation, but #getExtras
is meant for preferences that start another fragment through #setFragment
. Any extras specified on the preference are passed to the specified fragment, so long as you're using PreferenceActivity
.
Upvotes: 1
Reputation: 67502
what is the purpose of getExtras()?
It doesn't really do anything useful. Seriously.
In the Preference
source code, there is a private
member variable mExtras
:
private Bundle mExtras;
However, it's never changed in any way (and cannot be accessed by outside classes whatsoever), except in the following:
public Bundle getExtras() {
if (mExtras == null) {
mExtras = new Bundle();
}
return mExtras;
}
public Bundle peekExtras() {
return mExtras;
}
I suppose it might be used for something in the future, but it was added in API 11 and remains useless through API 16.
There is no method putExtra/s() in the Preference class, then... In which scenrarios is it used?
I guess you could use it for associating items with a preference, like:
Bundle extras = myPref.getExtras();
extras.putString("KEY", "Value");
You don't need putExtra()
to do so, instead accessing the Bundle
directly. But that's about all it's useful for, it seems.
Upvotes: 5