6

我尝试使用 BackupAgent 来备份我的默认值sharedpreferences。这就是我想要的MyBackupAgent

public class MyBackupAgent extends BackupAgentHelper {

    // The name of the SharedPreferences file
    private final String PREFS = "com.mikebdev.refuelpro_preferences";

    // A key to uniquely identify the set of backup data
    private static final String PREFS_BACKUP_KEY = "prefs";


    @Override
    public void onCreate() {
        SharedPreferencesBackupHelper sharedPref = new SharedPreferencesBackupHelper(this, PREFS);
        addHelper(PREFS_BACKUP_KEY, sharedPref);

    }
}

当从 ADB 强制备份和恢复时,这是我在控制台中得到的:

shell@flo:/ $ bmgr backup com.mikebdev.refuelpro
bmgr backup com.mikebdev.refuelpro
shell@flo:/ $ bmgr backup run
bmgr backup run
shell@flo:/ $ bmgr restore com.mikebdev.refuelpro
bmgr restore com.mikebdev.refuelpro
restoreStarting: 2 packages
restoreFinished: 0
done

这就是 Logcat 不得不说的:

09-20 18:47:32.125      525-539/? I/BackupManagerService﹕ Scheduling backup for new app com.mikebdev.refuelpro
09-20 18:47:32.125      525-539/? D/BackupManagerService﹕ Now staging backup of com.mikebdev.refuelpro
09-20 18:47:32.966     525-2458/? D/BackupManagerService﹕ agentConnected pkg=com.mikebdev.refuelpro agent=android.os.BinderProxy@42222800
09-20 18:52:00.336      525-539/? D/BackupManagerService﹕ Received broadcast Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:com.mikebdev.refuelpro flg=0x8000010 (has extras) }
09-20 18:52:00.336      525-539/? V/BackupManagerService﹕ removePackageParticipantsLocked: uid=10084 #1
09-20 18:52:08.344      525-546/? V/BackupManagerService﹕ restoreAtInstall pkg=com.mikebdev.refuelpro token=f restoreSet=39fa49811177c60b
09-20 18:52:08.354      525-657/? D/BackupManagerService﹕ MSG_RUN_RESTORE observer=null
09-20 18:52:08.935      525-657/? D/BackupManagerService﹕ initiateOneRestore packageName=@pm@
09-20 18:52:08.945      525-657/? V/BackupServiceBinder﹕ doRestore() invoked
09-20 18:52:08.945      525-657/? V/BackupManagerService﹕ No next package, finishing restore
09-20 18:52:08.945      525-657/? I/BackupManagerService﹕ Restore complete.

所以现在我想知道发生了什么,因为我还不知道。我不知道为什么这行不通。

而且,我将如何使用此服务备份一个小的 SQLite 数据库?

提前致谢

4

0 回答 0