user1562942
user1562942

Reputation:

Deprecated Preference Activity method

I am working with PreferenceActivity but when I call my preference xml(prefs.xml) with the help of addPreferencesFromResource() it says this method is deprecated and "This function is not relevant for a modern fragment-based PreferenceActivity". Is there any alternative of this method? How can I handle this?

package com.adi.preferencedemotest;

public class PrefsActivity extends PreferenceActivity {
    @SuppressWarnings("deprecation") <-------
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.prefs); <-------
    }

}

Note: may be my question rates as a duplicated but I didn't find any.

Upvotes: 8

Views: 9637

Answers (1)

StrikeForceZero
StrikeForceZero

Reputation: 2379

There aren't any documented alternatives that I know of. The method was deprecated in API 11 and from that API onwards you would create a class extending PrefrencesFragment and call the addPreferencesFromResource() method in the onCreate() there. Obviously that wouldn't work for on devices supporting API 10 and below.

Here is the answer I got my information from: What to use instead of "addPreferencesFromResource" in a PreferenceActivity?

Upvotes: 4

Related Questions