我已经阅读了文档和其他问题,但我想我遗漏了一些东西。我的 BackupAgentonCreate
被调用,但不是它onBackup
,即使我调用adb bmgr backup <package>
然后adb shell bmgr run
从命令行调用也是如此。我错过了方程式的哪一部分?
MyBackupAgent 类:
public class MyBackupAgent extends BackupAgentHelper {
public MyBackupAgent() {
Log.d("GradeTracker.MyBackupAgent", "onCreate called");
String str = DBAdapter.DATABASE_NAME;
FileBackupHelper myDb = new FileBackupHelper(this, "../databases/" + str);
addHelper(DBAdapter.DATABASE_NAME , myDb);
}
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
Log.d("GradeTracker.MyBackupAgent", "onBackup called");
synchronized (DBAdapter.dbBackupLockObject) {
super.onBackup(oldState, data, newState);
}
}
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState) throws IOException {
Log.d("GradeTracker.MyBackupAgent", "onRestore called");
synchronized (DBAdapter.dbBackupLockObject) {
super.onRestore(data, appVersionCode, newState);
}
}
}
在我的清单中:
<application
android:allowBackup="true"
android:backupAgent="MyBackupAgent"
...
<meta-data android:name="com.google.android.backup.api_key"
android:value="<my_key>" />
几个小时前,我才在 Android 备份服务中注册了我的应用程序,但它并没有说我必须等待。我错过了什么?