Android backup service - when and how often to backup?
Asked Answered
E

2

15

I want to backup my app's data using Android backup service, but I'm concerned about network usage. I have about 500KB of data that needs to be uploaded for each backup operation. Not much, but if the backup is performed 10 times per day, it can easily reach 5MB.

My question is, when and how often does Android decides to perform backup? The documentation only mentions "at an opportune time in the future" after I call dataChanged(). It doesn't explain what conditions constitute an "opportune time".

You can request a backup operation at any time by calling dataChanged(). This method notifies the Backup Manager that you'd like to backup your data using your backup agent. The Backup Manager then calls your backup agent's onBackup() method at an opportune time in the future.

Esurient answered 24/2, 2013 at 5:34 Comment(3)
have you found an answer? Probably, some logging could help to collect some statistics.Morbilli
@Andree: I have the same question. Do you have your answer yet? For mycase. I have about 1MB data uploaded (User local sqlite data) for each backup operation.Duchy
@Loc Ha: Sorry, I haven't. I'll put a bounty in this question to get more attention.Esurient
Y
13

There are 2 parts to your question:

  1. When
  2. How Often

Let's start with #2, how often. I think the documentation sufficiently answers this. Any time your app calls the dataChanged() method, there is the possibility of a backup. Thus would be prudent to limit the frequency of calls to this method. It is up to you how to handle this. One approach you might want to consider it to only call this for significant/important data changes in your app. That is, do not call it for changes to user preferences (like background color e.g.), but do call it for any sort of transactional data.

As for #1, when: That is harder to answer exactly. The documentation is noncommittal about this. This gives Android the freedom to change this algorithm, without violating any developer expectations. I do think it is reasonable to assume the following: the backup is likely to happen quickly, probably at the soonest time conditions are appropriate. If it did not happen "soon", then it would not be a very useful service, would it? There are probably some simple conditions that Android waits for (just a guess but this might be available threads, available network connection with no other network activity). Note that the documentation states "it will back up using whichever transport is enabled on the device". That sounds like it is designed to make the backup happen as early as possible.

Yann answered 3/1, 2015 at 4:48 Comment(2)
Good answer for a broad and difficult question (because the documentation does not say, so only Google truly knows). I agree with both your points.Etamine
How often it happens depends on the version of Android, really. Prior to Android L the first backup pass would happen around 12 hours following setup of the device; then after that, backups would happen within ~1 hour after any app called dataChanged(). In later versions of Android things have gotten a bit more relaxed; it's more like 4 hours now from dataChanged() to when the backup will actually run. This is for the older key/value API. Full-data backups, new in Android M, are only run when the device is idle and connected to wifi.Frothy
V
2

I've dove further on researching the Android Backup Manager Service and discovered the following:

  1. According to "Requesting Backup Section" in http://developer.android.com/guide/topics/data/backup.html "If you call dataChanged() several times consecutively, before the Backup Manager requests a backup from your agent, your agent still receives just one call to onBackup()."

I interpret this as each DataChanged() call in our App notifies the Backup Manager Service via transport. The Backup Manager Service will only perform ONE call to our App's Backup Agent's onBackup(), even if DataChanged gets called several times before the Backup Manager Service responds when it wants to (see item 2 below on Backup Manager respond frequency).

  1. According to this Tester (I also ran a backup frequency test just now): https://advancedweb.hu/2014/12/09/practical_measurement_of_the_android_backup_manager/ The Backup Manager Service responds every hour (I also proved this in my tests) as long as at least one DataChanged() was called in-between the hour since the last data backup.
Vagrant answered 11/2, 2016 at 23:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.