8

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.

4

1 回答 1

4

我知道没有任何记录在案的替代方案。该方法在 API 11 中已弃用,从该 API 开始,您将创建一个扩展类PrefrencesFragment并在 ) 中调用该addPreferencesFromResource()方法onCreate(。显然,这不适用于支持 API 10 及更低版本的设备。

这是我从中获得信息的答案: 在 PreferenceActivity 中使用什么来代替“addPreferencesFromResource”?

于 2012-09-04T03:34:36.607 回答