其实,getDefaultSharedPreference()方法中调用了getSharedPreferences()方法,而名称默认为 包名+_preferences,并且默认为私有模式
- /**
- * Gets a SharedPreferences instance that points to the default file that is
- * used by the preference framework in the given context.
- *
- * @param context The context of the preferences whose values are wanted.
- * @return A SharedPreferences instance that can be used to retrieve and
- * listen to values of the preferences.
- */
- 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;
- }