I'm currently taking the "Developing Android Apps" Udacity course. In the "Lesson 3: New Activities and Intents > Use SharedPreferences" segment, the instructor asked me to dig around the Android Developer site for how to get the user preferences from SharedPreferences
. However, I found it different between the official documentation and the course's solution.
The Udacity course's solution says, to grab a SharedPreferences
instance for the PreferenceActivity
, you should call:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
(where getActivity()
is simply the Context
here because it's called inside a Fragment
.)
While the official documentation on Android Developer Site indicates that you should call:
SharedPreferences prefs = getActivity().getPreferences(Context.MODE_PRIVATE)
So what's the difference between PreferenceManager.getDefaultSharedPreferences(Context context)
and Activity.getPreferences(int mode)
?
Please note: This question does not involve anything about getSharedPreferences()
which requires a file name. It's about the difference between getPreferences()
and getDefaultSharedPreferences()
.
Thanks in advance.