I am making a live wallpaper for Android. I have the wall paper part working and am trying to add settings to it. In LiveWallpaperSettings I have this:
@Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
getPreferenceManager().setSharedPreferencesName(LiveWallpaperService.SHARED_PREFS_NAME);
addPreferencesFromResource(R.string.livewallpaper_settings);
getPreferenceManager().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}
The compiler says that getPreferenceManager()
and addPreferencesFromResource()
are deprecated. What should I be using instead?
These methods are from PreferenceActivity
[Edit]: Based on the handful of comments thus far, I apparently am using an antiquated approach. Can someone point to a contemporary example of code for LiveWallpaper using PreferenceFragments?
https://github.com/falsedmitri/LiveWallpaperTest.git
From the documentation for 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.
So you can either switch to using Fragments or you can ignore these warnings. (Understand that deprecated methods will disappear from the API someday...)
Can someone point to a contemporary example of code for LiveWallpaper using PreferenceFragments?
There isn't a major difference between the methods used in PreferenceActivities and PreferenceFragments, switching to Fragments in general is the big change. But PreferenceFragment has an example and you see you can still use methods like addPreferencesFromResource()
in it's modern form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With