BackupAgentHelper:不会调用onRestore [英] BackupAgentHelper: onRestore not getting called
问题描述
我从此链接安装了示例BackupRestore。
I installed the example BackupRestore from this link.
我无法还原数据。
OnBackup和OnCreate被调用,但是OnRestore没有。
OnBackup and OnCreate get called, but OnRestore does not.
我能够备份:OnCreate和OnBackup被命中,但是OnRestore
I am able to backup: OnCreate and OnBackup get hit, but OnRestore does not.
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState) throws IOException {
// Hold the lock while the FileBackupHelper restores the file from
// the data provided here.
synchronized (BackupRestoreActivity.sDataLock) {
super.onRestore(data, appVersionCode, newState);
}
}
public void onRestoreButtonClick(View v) {
Log.v(TAG, "Requesting restore of our most recent data");
mBackupManager.requestRestore(
new RestoreObserver() {
public void restoreFinished(int error) {
/** Done with the restore! Now draw the new state of our data */
Log.v(TAG, "Restore finished, error = " + error);
populateUI();
}
}
);
}
我尝试使用adb工具(requestRestore除外),但它不起作用
I have tried using the adb tools (besides requestRestore) and it is not working either.
adb shell bmgr restore [package]
adb uninstall [apkfile]
adb install [apkfile]
运行恢复时,我得到:
restoreStarting: 1 packages
restoreFinished: 0
done
但是OnRestore不会被命中,并且数据也不会恢复。
But OnRestore does not get hit, and the data is not restored.
我正在使用Android Studio 3.0。我为此花了很多时间。有人可以揭露些什么吗?
I am using Android Studio 3.0. And I have spent many hours on this. Can anyone shed some light?
推荐答案
检查日志后,我注意到一条消息:
After checking the logs, I noticed a message:
I /备份:[KeyValueRateLimiter] [包]的K / V备份被速率限制器中止。 next = 1519165401410,current = 1519088429345
I/Backup: [KeyValueRateLimiter] K/V backup for [package] aborted by rate limiter. next=1519165401410, current=1519088429345
所以这意味着直到2018年2月20日下午5:23:21才进行备份。使用Google Transport进行备份存在速率限制,因此我将尝试没有速率限制的Local Transport。
So that means the backups are not being made until 2/20/2018, 5:23:21 PM. There is a rate limit for backups with Google Transport, so I am going to try Local Transport which has no rate limit.
更新:切换到Local Transport似乎可行。在我的设备上卸载/重新安装应用后,它能够恢复这些值。
Update: Switching to Local Transport seems to work. It was able to restore the values after an app uninstall/reinstall on my device.
这是我要使其正常工作的方法:
Here is what I did to get it to work:
- 将BackupRestore项目中的源文件复制到新项目中。
- 从此网站生成清单文件的备份密钥: https://developer.android.com/google/backup/signup.html
- 运行 adb shell bmgr列表传输以查看传输。
- 运行 adb shell bmgr传输android / com.android.internal.backup.LocalTransport 更改为本地传输(Google传输将施加速率限制)
- 运行adb shell bmgr backup [package]- -备份应用程序
- 运行 adb shell dumpsys backup 以查看挂起的备份文件
-
adb shell bmgr运行
- Copy the source files from the BackupRestore project into a new project.
- Generate the Backup key for the manifest file from this website: https://developer.android.com/google/backup/signup.html
- Run adb shell bmgr list transports to see the transports.
- Run adb shell bmgr transport android/com.android.internal.backup.LocalTransport to change the transport to Local (Google transport will impose a rate limit)
- Run adb shell bmgr backup [package] -- to backup app
- Run adb shell dumpsys backup to see the pending backup files
adb shell bmgr run
adb卸载[软件包名称]
adb uninstall [package name]
adb install -t [apk文件](用于调试时,我使用-t)
adb install -t [apk file] (for debugging I used -t)
检查是否已恢复值在安装过程中。
Check that the values were restored during the install.
我为此感到困惑。我希望这对某人有帮助。
I struggled with this. I hope this helps someone.
这篇关于BackupAgentHelper:不会调用onRestore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!