Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android backup service - when and how often to backup?

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.

like image 248
Andree Avatar asked Feb 24 '13 05:02

Andree


Video Answer


1 Answers

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.

like image 68
EJK Avatar answered Sep 27 '22 17:09

EJK