安卓云——备份管理器 vs Drive

3
我正在开发一个应用程序,希望实现一个功能,可以在同一用户的多个设备之间分享收藏夹、书签等内容。所以,我想实现类似iCloud的东西。
我找到了两个可能的解决方案:备份管理器和Google Drive。我认为备份管理器是最简单的解决方案,并且符合我的需求,但也许我错了:
注意:备份服务不适用于将应用程序数据与其他客户端同步或保存您想要在正常应用程序生命周期内访问的数据。您不能按需读取或写入备份数据,并且除了通过备份管理器提供的API之外,无法以任何方式访问它。

Note: The backup transport provided by Android Backup Service is not guaranteed to be available on all Android-powered devices that support backup. Some devices might support backup using a different transport, some devices might not support backup at all, and there is no way for your application to know what transport is used on the device.

Since I'm storing this information in SharedPreferences I started my implementation by extending BackupAgentHelper as Google advises (http://developer.android.com/guide/topics/data/backup.html#BackupAgentHelper).

...each time the user changes some data, your app should call dataChanged(), which adds a backup request to the Backup Manager queue.

So, each time I change data, save or remove a bookmark for example, I call:

BackupManager.dataChanged(C.PROJECT_PATH);

When my applications starts I call:

contentBackupManager.requestRestore(new RestoreObserver() {})

Everything is setup and AndroidManifest.xml too.

Unfortunately requestRestore is returning != 0 (error) and my BackupAngent (extends BackupAgentHelper) onBackup and onRestore aren't being called (onCreate is). But, once again:

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 this means I'll only find my answer in Google Drive?


备份服务用于在用户重新安装应用程序时恢复用户偏好设置。在您发布的说明中,指出不要使用备份服务来执行您正在尝试执行的操作。那么,为什么您还要尝试这样做呢? - Robby Pond
1个回答

6
您是正确的,不应该使用BackupManager来进行此操作。您需要使用第三方服务来保存您的确切数据类型。因此,您可以选择以下两种方式之一:
  • 使用提供API的服务(如Google Drive或Dropbox)上传(和下载)任何类型的文件,并将数据存储在您选择的格式(XML / JSON /二进制)中。优点是:
    • 您无需为数据存储编写服务器端应用程序,因此开发工作量较小
    • 用户拥有自己的数据,这对某些用户非常重要
  • 编写一些定制的服务器端代码,以提供特定于您的应用程序的API。您可以使用Google App Engine进行此操作。显然,缺点是增加了开发工作量,并且如果您有很多用户,则可能会产生来自appengine的账单。但是,如果您选择这条路线,您还具有多个优势:
    • 您不会浪费用户Drive或Dropbox帐户的空间,
    • 用户不喜欢在第三方应用程序中输入他们的Drive / Dropbox凭据,
    • 您可以使用诸如GCM等巧妙功能,
    • 您将数据存储在实际数据库中,因此可以按照您的意愿对其进行结构化,并且您也拥有它。

由您决定 :)


1
谢谢您的回复。在这种情况下,我认为我会使用Google Drive或Dropbox API而不是Google App Engine,因为这个应用程序不会使用服务器端。;) - GuilhE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接