Android 2.2数据备份:使用PreferenceActivity时如何备份?
我想使用备份代理来保存用户首选项:
http://developer .android.com/guide/topics/data/backup.html
文章中,解释了如何备份 SharedPreferences:
http://developer.android.com/guide/topics/data/backup.html #SharedPreferences
但是没有解释如何在使用 PreferenceActivity (http://developer.android.com/reference/android/preference/PreferenceActivity.html) 来保存用户首选项时进行备份!
我的应用程序有一个扩展 PreferenceActivity 的设置活动,它从preference.xml 文件(其中配置了 PreferenceScreen)加载设置。当显示 PreferenceActivity 时,用户可以设置首选项的值。如何使用数据备份 API 通过 PreferenceActivity 保存用户数据集?
I'd like to use the backup agent for saving user preferences:
http://developer.android.com/guide/topics/data/backup.html
In the article, it's explained how to backup SharedPreferences:
http://developer.android.com/guide/topics/data/backup.html#SharedPreferences
However it's not explained how to backup when a PreferenceActivity (http://developer.android.com/reference/android/preference/PreferenceActivity.html) is used to save user preferences!
My application has a Setting Activity extending PreferenceActivity, which loads the settings from a preference.xml file (where a PreferenceScreen is configured). When the PreferenceActivity is displayed, the user can set the values of the preferences. How can I use the Data Backup API to save user data set with a PreferenceActivity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SharedPreferences 是一个可以访问 PreferenceActivity 生成的首选项的类。换句话说,默认首选项使用sharedPreferences 类,就像您手动操作一样。它使用的密钥当然是您在preferences.xml中提供的密钥,
因此您可以使用SharedPreferences,如您提供的链接中详细说明的,以及首选项活动为您添加的设置。
SharedPreferences is a Class with access to the preferences that the PreferenceActivity generats. In other word the default preferences use the sharedPreferences class the same way you would if you did it manualy. The key it usus is of course the key you gave it in the preferences.xml
Therefore you can use SharedPreferences as detailed in the link you provided with the settings which the preference activity added for you.