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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…