[英]Which to use for settings activity : preferences api or sharedpreferences?
I have a settings activity
for users in my application. 我的应用程序中有一个针对用户的设置activity
。 I manually add the changes to a sharedpreferences
file ( simple delete , edit , add operations ). 我将更改手动添加到sharedpreferences
文件(简单的delete,edit和add操作)。 It works fine but just now i heard of preferences activity
. 它工作正常,但刚才我听说了偏好activity
。 Should i use it instead? 我应该改用它吗?
PreferenceActivity
and Fragment
provide some advantages: PreferenceActivity
和Fragment
提供了一些优点:
In the end you can achieve the same results with both approaches, but I recommend using the Preferences Activity/Fragment
for the consistency with the system and avoiding boilerplate code or bugs that may appear from implementing the preferences yourself. 最后,您可以通过两种方法获得相同的结果,但是我建议使用“ Preferences Activity/Fragment
”以与系统保持一致,并避免样板代码或自己实现首选项可能出现的错误。
Check these tutorials for more info: http://android-pro.blogspot.com.eg/search/label/SharedPreferences 查看这些教程以获取更多信息: http : //android-pro.blogspot.com.eg/search/label/SharedPreferences
https://developer.android.com/reference/android/preference/PreferenceFragment.html https://developer.android.com/reference/android/preference/PreferenceFragment.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.