What is the difference between getDefaultSharedPreferences
and getSharedPreferences
in Android? Can anyone please explain?
getDefaultSharedPreferences
will use a default name like "com.example.something_preferences", but getSharedPreferences
will require a name.
getDefaultSharedPreferences
in fact uses Context.getSharedPreferences
(below is directly from the Android source):
public static SharedPreferences getDefaultSharedPreferences(Context context) {
return context.getSharedPreferences(getDefaultSharedPreferencesName(context),
getDefaultSharedPreferencesMode());
}
private static String getDefaultSharedPreferencesName(Context context) {
return context.getPackageName() + "_preferences";
}
private static int getDefaultSharedPreferencesMode() {
return Context.MODE_PRIVATE;
}