Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Backup API

Can anyone explain what exactly the Android Backup API is used for?

I have read Using the Backup API and Data Backup from the Developer Docs, but it is still unclear to me.

When is data backed up & restored?

Specifically in these situations:

  1. A user installs my app on Device 1, data is backed up, and the user then installs my app on Device 2. Is user data from Device 1 automatically put on Device 2? If so, does this occur when the app is installed or when it is launched?

  2. My app is installed on 2 devices. When a change is made on Device 1 is it automatically made on Device 2? If not, is it at least possible to make the change on Device 2?

In one doc, it says

The backup service is not designed for synchronizing application data with other clients or saving data that you'd like to access during the normal application lifecycle. You cannot read or write backup data on demand and cannot access it in any way other than through the APIs provided by the Backup Manager.

But in another,

the Android framework helps you build rich cloud-enabled apps that sync their data to a remote web service, making sure all your devices always stay in sync

This seems like a contradiction to me.

More specifically, I want to continually sync a single database file (less than 20 KB) across devices. Is this possible with the Backup API?

like image 986
Matt Robertson Avatar asked Jan 13 '13 01:01

Matt Robertson


1 Answers

Edit: So to answer your question - no, it is not a reliable way to sync your data.

When a user purchases a new device or resets their existing one, they might expect that when Google Play restores your app back to their device during the initial setup, the previous data associated with the app restores as well. By default, that doesn't happen and all the user's accomplishments or settings in your app are lost.

As I see it your app is storing data to the cloud. You push the files to the backup servers and with the API key (that is unique to each users google account) allows you to download the backup to other devices but can only be accesses during the install of the app or by doing a manual request. The documentation states:

The backup service is not designed for synchronizing application data with other clients or saving data that you'd like to access at random during the application lifecycle.

As I understand it (without having implemented this my self) you cannot use this as a reliable method for cloud syncing real-time data.

The manifest will probably launch the processing of your data and determine if a backup should be pushed.

At some point in the future, the backup manager then calls your backup agent's onBackup() method

Restoring a backup is not manual:

Typically you shouldn't ever have to manually request a restore, as it happens automatically when your application is installed on a device. However, if it is necessary to trigger a manual restore, just call the requestRestore() method.

like image 121
Daniel Avatar answered Oct 03 '22 22:10

Daniel