Android backup service - when and how often to backup?

前端 未结 2 768
北恋
北恋 2020-12-29 08:04

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 op

2条回答
  •  遥遥无期
    2020-12-29 09:08

    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.

提交回复
热议问题