The code that calls this is in Preference#performClick(PreferenceScreen preferenceScreen) , and it does the following:
PreferenceManager preferenceManager = getPreferenceManager(); if (preferenceManager != null) { PreferenceManager.OnPreferenceTreeClickListener listener = preferenceManager .getOnPreferenceTreeClickListener(); if (preferenceScreen != null && listener != null && listener.onPreferenceTreeClick(preferenceScreen, this)) { return; } } if (mIntent != null) { Context context = getContext(); context.startActivity(mIntent); }
return true will return immediately, returning false , will check if an Intent exists for this PreferenceScreen and run the specified Activity .
If you return super.onPreferenceTreeClick(preferenceScreen, preference) , you will also call the following PreferenceFragment code snippet to run
if (preference.getFragment() != null && getActivity() instanceof OnPreferenceStartFragmentCallback) { return ((OnPreferenceStartFragmentCallback)getActivity()).onPreferenceStartFragment( this, preference); } return false;
This checks if there is a Fragment to be displayed . If not Preference will look for Intent .
TL; DR
Preferences can start with either Intent or Fragment s. Return value
true : nothing happens, fragments and intent are ignoredfalse : fragments are ignored, intentions are executedsuper.onPreference.. : first tries to fragment the fragment, and the second -
return false; or return super.onPreferenceTreeClick(...) should usually be returned. The meaning of the return value is approximately "Start activity on purpose, if exists?". You must return true if you specified the intention, but do not want to run it. This does not matter in most other cases, as you rarely process clicks if you have this intention.
source share