1
MyBackupAgentHelper.javaSharedPreferences備份工作不
public class MyBackupAgentHelper extends BackupAgentHelper {
private static final String MESSAGE_DB_FILE_BACKUP_KEY = "MESSAGE_DB_FILE_BACKUP_KEY";
private static final String DEFAULT_SHARED_PREFRERNCES_KEY = "DEFAULT_SHARED_PREFRERNCES_KEY";
@Override
public void onCreate() {
super.onCreate();
LogUtil.pd();
File file = MessageDao.getSingleton(this).getSQLite().getFile();
if (file == null) {
LogUtil.w("Messsage DB File is NULL !");
} else {
LogUtil.i("Messsage DB File: "+file.getAbsolutePath());
FileBackupHelper backupHelper = new FileBackupHelper(this, file.getName());
addHelper(MESSAGE_DB_FILE_BACKUP_KEY, backupHelper);
}
String prefName = getDefaultSharedPreferencesName(this); // It return "my.package.name_preferences"
LogUtil.i("Default Shared Preferences Name: "+prefName);
SharedPreferencesBackupHelper backupHelper = new SharedPreferencesBackupHelper(this, prefName);
addHelper(DEFAULT_SHARED_PREFRERNCES_KEY, backupHelper);
}
登錄貓
03-26 10:11:02.361: I/MyPackage(3540): Messsage DB File: /data/data/my.package.name/files/db.sqlite
03-26 10:11:02.361: I/MyPackage(3540): Default Shared Preferences Name: my.package.name_preferences
數據目錄文件樹(數據/數據/ my.package.name)
03-26 10:09:22.291: I/MyPackage(3540): my.package.name
03-26 10:09:22.291: I/MyPackage(3540): -shared_prefs
03-26 10:09:22.291: I/MyPackage(3540): --my.package.name_preferences.xml
03-26 10:09:22.291: I/MyPackage(3540): -files
03-26 10:09:22.291: I/MyPackage(3540): --db.sqlite
03-26 10:09:22.291: I/MyPackage(3540): -lib
我被迫通過adb shell進行備份,刪除了我的應用,並重新安裝了我的應用。
我檢查備份&恢復db.sqlite文件(它工作正常。)
但默認SharedPreferences未恢復或備份的。
我該如何備份&恢復默認SharedPreferences?
MODE_PRIVATE仍允許使用備份APIS保存sharedPreference – coolcool1994