PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);

作用: 可以偷懒 少写一个文件名和模式

private static String getDefaultSharedPreferencesName(Context context) {
    return context.getPackageName() + "_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());
}
发布了9 篇原创文章 · 获赞 0 · 访问量 1184

猜你喜欢

转载自blog.csdn.net/weixin_42349862/article/details/105259214