Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getPreferenceManager deprecated

Tags:

android

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

like image 721
Al Lelopath Avatar asked Oct 22 '22 13:10

Al Lelopath


1 Answers

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.

like image 109
Sam Avatar answered Oct 31 '22 12:10

Sam