android - getPreferenceManager 已弃用

标签 android

我正在为 Android 制作动态壁纸。我的墙纸部分正在工作,我正在尝试为其添加设置。在 LiveWallpaperSettings 我有这个:

@Override
protected void onCreate(Bundle icicle)
{
    super.onCreate(icicle);
    getPreferenceManager().setSharedPreferencesName(LiveWallpaperService.SHARED_PREFS_NAME);
    addPreferencesFromResource(R.string.livewallpaper_settings);
    getPreferenceManager().getSharedPreferences()
            .registerOnSharedPreferenceChangeListener(this);
}

编译器表示 getPreferenceManager()addPreferencesFromResource() 已弃用。我应该改用什么?

这些方法来自PreferenceActivity

[编辑]:根据到目前为止的一些评论,我显然使用了一种过时的方法。有人可以指出使用 PreferenceFragments 的 LiveWallpaper 代码的现代示例吗?

https://github.com/falsedmitri/LiveWallpaperTest.git

最佳答案

来自 the documentation对于 PreferenceActivity:

Prior to HONEYCOMB this class only allowed the display of a single set of preference; this functionality should now be found in the new PreferenceFragment class. If you are using PreferenceActivity in its old mode, the documentation there applies to the deprecated APIs here.

因此您可以切换到使用 Fragments,也可以忽略这些警告。 (了解过时的方法总有一天会从 API 中消失...)


Can someone point to a contemporary example of code for LiveWallpaper using PreferenceFragments?

在 PreferenceActivities 和 PreferenceFragments 中使用的方法之间没有重大区别,切换到 Fragments 通常是一个很大的变化。但是PreferenceFragment有一个示例,您会发现您仍然可以使用现代形式的 addPreferencesFromResource() 等方法。

关于android - getPreferenceManager 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15706179/

相关文章:

java - Android,在启动模拟器时启动应用程序

java - 我需要声明一个可绘制变量吗?

android - Kotlin 中 Holdr 的未解决引用

android - 在 x86_64 linux 机器上编译 gentoo-bionic

android - Retrofit 不支持 CLEARTEXT 通信

带有 IFrame 的 Android Cordova 应用程序 Chrome 63 无请求 header Cookie

android - 区分缩放手势检测器android中的放大和缩小

Android GPS在计算距离的精度问题

java - 如何将 OnItemClickListener 添加到可扩展 ListView 中的子项

android - 如何在Android Studio中查看支持库文档?