Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

android - BackupManager Not Calling Backup Transport

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"

as well as

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

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();

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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) 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...