The main difference is in their names, PreferenceManger gives the developer access to various functions for managing SharedPreferences , for example, to get a map of current preference values ββor customize user settings. to their default values. PreferenceScreen handles the display of user preferences so that the user can assign values ββto them. Sometimes this means displaying a list item on a screen with different settings, which opens another screen with a lot of preferences when clicked, as in the case when PreferenceScreen are nested.
Your question implies that you think there is a difference between what PreferenceManager.getSharedPreferences() and PreferenceScreen.getSharedPreferences() , but they are identical according to the source code.
PreferenceScreen :
public SharedPreferences getSharedPreferences() { if (mPreferenceManager == null) { return null; } return mPreferenceManager.getSharedPreferences(); }
Thus, PreferenceManger and PreferenceScreen are different entities, but SharedPreference returns this method as the same object, since PreferenceScreen calls the method from PreferenceManager . Hope this is the answer you were looking for.
If you have a choice, go to PreferenceManager.getSharedPreferences() , this will become more obvious and will call one method inside.
Fun fact:
PreferenceFragment :
public PreferenceManager getPreferenceManager() { return mPreferenceManager; } public PreferenceScreen getPreferenceScreen() { return mPreferenceManager.getPreferenceScreen(); }
Dandre Allison Dec 18 2018-12-12T00: 00Z
source share