我正在实现 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
?)