Android 2.2数据备份:如何备份DefaultSharedPreferences?
我正在实现 Android OS 2.2 中的新 BackupAgentHelper
。
为了使其工作,您需要提供要备份的 SharedPreferences
的名称:
public class MyPrefsBackupAgent extends BackupAgentHelper {
// The name of the SharedPreferences file
static final String PREFS = "user_preferences";
// A key to uniquely identify the set of backup data
static final String PREFS_BACKUP_KEY = "prefs";
// Allocate a helper and add it to the backup agent
void onCreate() {
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
addHelper(PREFS_BACKUP_KEY, helper);
}
}
问题是我在应用程序中使用 PreferenceManager.getDefaultSharedPreferences()
方法来获取默认共享首选项实例。现在我需要提供该文件的名称。我怎样才能知道那是什么名字?
(为什么他们不提供一个只执行 DefaultSharedPreferences
备份的助手?)
I am implementing the new BackupAgentHelper
from Android OS 2.2.
For it to work you need to supply the name of the SharedPreferences
that you want to backup:
public class MyPrefsBackupAgent extends BackupAgentHelper {
// The name of the SharedPreferences file
static final String PREFS = "user_preferences";
// A key to uniquely identify the set of backup data
static final String PREFS_BACKUP_KEY = "prefs";
// Allocate a helper and add it to the backup agent
void onCreate() {
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
addHelper(PREFS_BACKUP_KEY, helper);
}
}
Problem is I use the PreferenceManager.getDefaultSharedPreferences()
method in my application to get the default shared preferences instance. Now I need to supply the name of that file. How can I find out what name that is?
(And why do they not supply a helper that just does a DefaultSharedPreferences
backup?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来它的名字是
“packagename_preferences”
It looks like it's called
"packagename_preferences"