Android备份服务-备份时间和频率? [英] Android backup service - when and how often to backup?

查看:115
本文介绍了Android备份服务-备份时间和频率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Android备份服务备份我的应用程序的数据,但是我担心网络用法。每个备份操作需要上载约500KB的数据。数量不多,但是如果每天执行10次备份,则轻松达到5MB。

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.

我的问题是,Android决定何时以及多久执行一次备份?在我调用 dataChanged()之后,文档仅提及将来的适当时机。它并没有说明什么条件构成了最佳时机。

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".


您可以随时通过调用$ b $来请求备份操作b dataChanged()。此方法通知备份管理器您希望
使用备份代理备份数据。然后,备份管理器
在将来
的适当时间调用备份代理的 onBackup()方法。

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.


推荐答案

问题有两部分:


  1. 何时

  2. 多久

让我们从#2开始,多久。我认为文档足以回答这个问题。每当您的应用程序调用 dataChanged()方法时,就有可能进行备份。因此,最好限制对此方法的调用频率。如何处理这个问题取决于您。您可能要考虑的一种方法是仅对应用程序中的重要/重要数据更改进行调用。也就是说,不要为更改用户首选项(例如背景颜色)而调用它,而应为任何类型的交易数据调用它。

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.

对于#1,何时:这很难准确回答。该文档对此是不容置疑的。这使Android可以自由更改此算法,而不会违反任何开发人员的期望。我确实认为有以下假设是合理的:备份可能很快发生,可能在最快的条件下才发生。如果它不是很快发生的,那么它将不是非常有用的服务,对吗? Android可能会等待一些简单的条件(只是一个猜测,但这可能是可用的线程,可用的网络连接而没有其他网络活动)。请注意,文档指出 它将使用设备上启用的任何传输进行备份。这听起来像是旨在使备份尽早进行。

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.

这篇关于Android备份服务-备份时间和频率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆