问题描述
当我试图效仿Android的开发者指南和教程使用preferences创建设置的活动,我收到警告,如:
的方法,从类型$ P $ pferenceActivity增加preferencesFromResource(INT)是pcated德$ P $
对于无论是在code这些行:
获取preferenceManager()setShared preferencesName(preFS_NAME)。
加preferencesFromResource(R.xml.default_values);
我知道这些都只是警告,但我不知道他们是否会造成任何问题,现在还是将来,当我运行了我设计的应用程序。
公共类DefaultValues扩展preferenceActivity {
静态最后弦乐preFS_NAME =默认;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
获得preFS(本);
获得preferenceManager()setShared preferencesName(preFS_NAME)。
加preferencesFromResource(R.xml.default_values);
}
静态共享preferences得到preFS(上下文的背景下){
preferenceManager.setDefaultValues(背景下,preFS_NAME,MODE_PRIVATE,
R.xml.default_values,假);
返回context.getShared preferences(preFS_NAME,MODE_PRIVATE);
}
}
由于方法去precated,建议您不要在code使用它,因为它是完全可能的,它可以在Android的未来版本中删除。但是,我还没有遇到那个实际上已经从Android的去除脱precated方法。
没有可供选择的方法,提供的方法中的描述,因为preferred方法(如API 11水平的)是实例<一href="http://developer.android.com/reference/android/$p$pference/$p$pferenceFragment.html">$p$pferenceFragment对象从资源文件加载preferences。见样品code在这里:<一href="http://developer.android.com/reference/android/$p$pference/$p$pferenceActivity.html">$p$pferenceActivity
When I attempt to follow Android's Developer guides and tutorials for creating a Settings Activity using Preferences, I receive warnings such as:
"The method addPreferencesFromResource(int) from the type PreferenceActivity is deprecated"
for both of these lines in the code:
getPreferenceManager().setSharedPreferencesName(PREFS_NAME);
addPreferencesFromResource(R.xml.default_values);
I know these are just warnings, but I was wondering if they will cause any issues, now or in the future, when I am running the application that I am designing.
public class DefaultValues extends PreferenceActivity {
static final String PREFS_NAME = "defaults";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPrefs(this);
getPreferenceManager().setSharedPreferencesName(PREFS_NAME);
addPreferencesFromResource(R.xml.default_values);
}
static SharedPreferences getPrefs(Context context) {
PreferenceManager.setDefaultValues(context, PREFS_NAME, MODE_PRIVATE,
R.xml.default_values, false);
return context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
}
}
As the method is deprecated, it is recommended that you don't use it in your code, as it is entirely possible that it can be removed in future versions of Android. However, I am yet to come across a deprecated method that has actually been removed from Android.
No alternative method is provided in the method's description because the preferred approach (as of API level 11) is to instantiate PreferenceFragment objects to load your preferences from a resource file. See the sample code here: PreferenceActivity
这篇关于关于preferenceActivity Android-德precated方法警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!