BackupManager不调用备份传输 [英] BackupManager Not Calling Backup Transport

查看:223
本文介绍了BackupManager不调用备份传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我想实现数据备份到我的应用程序,并已按照本指南。我实现了我的 BackupAgentHelper 使用共享preferencesBackupHelper 。我没有得到任何错误,我是一定要叫 dataChanged()毕竟preference变化,但是当我测试备份(`ADB壳BMGR运行)我得到了LogCat中这样的信息:

Alright, so I'm trying to implement Data Backup into my application, and have been following this guide. I've implemented my BackupAgentHelper using a SharedPreferencesBackupHelper. I don't get any errors, and I'm being sure to call dataChanged() after all preference changes, but when I test the backup (`adb shell bmgr run) I get this information in LogCat:

07-07 12:29:00.258: V/BackupManagerService(291): Scheduling immediate backup pass
07-07 12:29:00.258: V/BackupManagerService(291): Running a backup pass
07-07 12:29:00.258: V/BackupManagerService(291): clearing pending backups
07-07 12:29:00.258: V/PerformBackupTask(291): Beginning backup of 1 targets
07-07 12:29:00.289: V/BackupServiceBinder(291): doBackup() invoked
07-07 12:29:00.289: D/PerformBackupTask(291): invokeAgentForBackup on @pm@
07-07 12:29:00.297: I/PerformBackupTask(291): no backup data written; not calling transport

所以,以供参考,在我的清单,我说:

So for reference, in my manifest I've added:

<application
        android:allowBackup="true"
        android:backupAgent="com.kcoppock.sudoku.SudokuBackupAgent"

以及

<meta-data
        android:name="com.google.android.backup.api_key"
        android:value="my_key_goes_here" />

和我的BackupAgentHelper是像这样实现的:

and my BackupAgentHelper is implemented like so:

public class SudokuBackupAgent extends BackupAgentHelper {
    static final String SCORES = "SCORES";
    static final String BACKUP_ID = "sudoku_backup";

    @Override
    public void onCreate() {
        SharedPreferencesBackupHelper backupHelper = 
                new SharedPreferencesBackupHelper(this, SCORES);
        addHelper(BACKUP_ID, backupHelper);
    }
}

最后,在我的主要活动,我呼吁这样的数据备份:

and finally, in my main activity, I call for a data backup like this:

edit.putString(id + "_values", valueCache.toString());
edit.putString(id + "_hints", hintCache.toString());
edit.commit();
BackupManager backup = new BackupManager(this);
backup.dataChanged();

我已经试过调试,看来我的的onCreate() SudokuBackupAgent 永远不会被调用。或者至少它从来没有从调试器到达。现在看来,这是没有找到任何更新的数据,和我有双重检查,以确保没有要备份的数据。是否有什么我失踪这里?

I've tried debugging, and it seems my onCreate() in SudokuBackupAgent is never called. Or at least it's never reached from the debugger. It seems it isn't finding any updated data, and I have double checked to ENSURE there is data to be backed up. Is there something I'm missing here?

修改:我补充一下,我测试的设备(Galaxy Nexus的)上,我已经用导出的发行APK用于测试目的甚至试图

EDIT: I should add, I'm testing on a device (Galaxy Nexus), and I've even tried using an exported release APK for testing purposes.

推荐答案

1)把Log.i()到您的onCreate,看它是否就是所谓的。

1) Put Log.i() into your onCreate, to see if it's called.

2)的logcat表明你的函数没有写任何东西。检查您是否有shared_ preFS /得分您的应用程序的私有文件夹文件(假定使用root权限的设备上适当的文件管理器)。这是你试图在备份文件。 也许你的preferences文件比这个文件别的东西,在这种情况下,解决您的字符串分数来反映现实preferences文件。

2) Logcat indicates that your function didn't write anything. Check if you have shared_prefs/SCORES file in your app's private folder (assumes using appropriate file manager on rooted device). This is the file you're attempting to have in backup. Probably your preferences file is something else than this file, in such case fix your String SCORES to reflect real preferences file.

3)我想在我的应用程序调试BackupAgentHelper.onCreate,它可以调用ADB壳BMGT后进行调试......所以有可能步在这里调试。

3) I tried to debug BackupAgentHelper.onCreate in my app, and it can be debugged after invoking adb shell bmgt... so it is possible to step here in debugger.

这篇关于BackupManager不调用备份传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆