Search code examples
androidandroid-backup-service

Android Backup service delay


I'm using the Android Backup Service in my current app. I've read on the docs that

A backup request does not result in an immediate call to your onBackup() method. Instead, the Backup Manager waits for an appropriate time, then performs backup for all applications that have requested a backup since the last backup was performed.

Does anyone know approximately how long can it take from the dataChanged() request to actual backup operation?

Or maybe it would be a good option to ditch the Android backup service altogether and select other storage?

Best regards!


Solution

  • The exact time from calling dataChanged() to the data actually being pushed to the backup storage backend will vary based on several factors: connectivity, principally. The version of Android that the device is running matters too; the delay policy has been tweaked over the years. The reason there's a delay at all is to avoid pushing a lot of data "unnecessarily," using up peoples' monthly data quota, while still trying to keep the backend at least mostly up to date, so that you don't lose tons of changes if you accidentally drop the phone in a river or something. Typically the latency is up to an hour, though as of Android M it's rather longer (more like 4 hours). For testing purposes you can always force an immediate backup pass with this adb command:

    adb shell bmgr run
    

    You can also simulate your app's calling dataChanged() first with a different call to the bmgr shell tool:

    adb shell bmgr backup com.myapps.packagename
    

    (only using whatever your app's package name really is, of course.)

    You don't say which data path your app is using -- full data (new in Android M) or key/value (introduced in Android Froyo). dataChanged() is only relevant for the older key/value API.

    As Viktor Yakunin above pointed out, backup is not sync: the goal of the backup system is to deliver the app's data seamlessly when the app is installed, either on a new device that the user is setting up, or following uninstall and reinstall of the app on the same device. If what you want is a data exchange mechanism, or maintaining identical data simultaneously across multiple devices, you should look at the Sync Manager or other similar 3rd party facilities.