Android databackup

1.7k views Asked by At

I am trying to implement the data backup in my application using data backup api.

The onBackup method in the BackupAgent helper class is never called. The Document says that the onBackup() will be called some time in the future. Is there any specific time when the onBackup will be invoked? Will it be invoked only once a day?

I tried to force the data backup on an emulator and a Nexus 7 device, using the following command:

adb shell bmgr backup <package>
adb shell bmgr run

The onBackup() implementation was called on the emulator but on the device it was never called. Will the bmgr tool work on the device? Please help me to understand.

2

There are 2 answers

2
J Rocks On

Check your Manifest file to see if under application you have android:allowBackup="true" as well as android:backupAgent having the correct path to your projects FileBackupAgent. Also, your meta-data should have your registered key, such as android:value="your-registerd-key"

Make sure your device is connected to a Wi-Fi network. Also, make sure in your device Settings, the Backup and Reset needs to have "Back up my data" checked, and "Backup account" has a valid gmail account, and "Automatic restore" is checked.

In addition, in a command window, your transport settings should be: *com.google.android.backup/.BackupTransportService

You can see this by typing: bmgr list transports If transport is set to local, then enter: adb shell bmgr transport com.google.android.backup/.BackupTransportService

Other bmgr commands to use to "kick" start your backup in https://www.google.com/settings/dashboard are:

 adb shell bmgr enabled 
 adb shell bmgr wipe "<package_name>"
 adb shell bmgr backup "<package_name>"
 adb shell bmgr run

Refresh your https://www.google.com/settings/dashboard to see the latest backup timestamp

0
live-love On

Run

adb shell bmgr transport android/com.android.internal.backup.LocalTransport 

to change the transport to Local (even though the documentation

https://developer.android.com/guide/topics/data/testingbackup.html#TestingBackup

suggests Google transport, it will impose a backup limit, and you will be only able to do a backup every 24 hours).

Run this command to kick start the backup:

adb shell bmgr run

The 'run' command causes any scheduled backup operation to be initiated immediately, without the usual waiting period for batching together data changes.

Run this to see pending backups:

adb shell dumpsys backup