Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top