Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

BackupManager

extends Object
java.lang.Object
   ↳ android.app.backup.BackupManager

Class Overview

The interface through which an application interacts with the Android backup service to request backup and restore operations. Applications instantiate it using the constructor and issue calls through that instance.

When an application has made changes to data which should be backed up, a call to dataChanged() will notify the backup service. The system will then schedule a backup operation to occur in the near future. Repeated calls to dataChanged() have no further effect until the backup operation actually occurs.

A backup or restore operation for your application begins when the system launches the BackupAgent subclass you've declared in your manifest. See the documentation for BackupAgent for a detailed description of how the operation then proceeds.

Several attributes affecting the operation of the backup and restore mechanism can be set on the <application> tag in your application's AndroidManifest.xml file.

Developer Guides

For more information about using BackupManager, read the Data Backup developer guide.

Summary

XML Attributes
Attribute Name Related Method Description
android:allowBackup Whether to allow the application to participate in the backup and restore infrastructure. 
android:backupAgent The name of the class subclassing BackupAgent to manage backup and restore of the application's data on external storage. 
android:killAfterRestore Whether the application in question should be terminated after its settings have been restored during a full-system restore operation. 
android:restoreAnyVersion Indicate that the application is prepared to attempt a restore of any backed-up dataset, even if the backup is apparently from a newer version of the application than is currently installed on the device. 
Public Constructors
BackupManager ( Context context)
Constructs a BackupManager object through which the application can communicate with the Android backup system.
Public Methods
void dataChanged ()
Notifies the Android backup system that your application wishes to back up new changes to its data.
static void dataChanged ( String packageName)
Convenience method for callers who need to indicate that some other package needs a backup pass.
int requestRestore ( RestoreObserver observer)
Restore the calling application from backup.
[Expand]
Inherited Methods
From class java.lang.Object

XML Attributes

android:allowBackup

Whether to allow the application to participate in the backup and restore infrastructure. If this attribute is set to false , no backup or restore of the application will ever be performed, even by a full-system backup that would otherwise cause all application data to be saved via adb. The default value of this attribute is true .

Must be a boolean value, either " true " or " false ".

This may also be a reference to a resource (in the form " @[ package :] type : name ") or theme attribute (in the form " ?[ package :][ type :] name ") containing a value of this type.

This corresponds to the global attribute resource symbol allowBackup .

Related Methods

android:backupAgent

The name of the class subclassing BackupAgent to manage backup and restore of the application's data on external storage.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form " @[ package :] type : name ") or theme attribute (in the form " ?[ package :][ type :] name ") containing a value of this type.

This corresponds to the global attribute resource symbol backupAgent .

Related Methods

android:killAfterRestore

Whether the application in question should be terminated after its settings have been restored during a full-system restore operation. Single-package restore operations will never cause the application to be shut down. Full-system restore operations typically only occur once, when the phone is first set up. Third-party applications will not usually need to use this attribute.

The default is true , which means that after the application has finished processing its data during a full-system restore, it will be terminated.

Must be a boolean value, either " true " or " false ".

This may also be a reference to a resource (in the form " @[ package :] type : name ") or theme attribute (in the form " ?[ package :][ type :] name ") containing a value of this type.

This corresponds to the global attribute resource symbol killAfterRestore .

Related Methods

android:restoreAnyVersion

Indicate that the application is prepared to attempt a restore of any backed-up dataset, even if the backup is apparently from a newer version of the application than is currently installed on the device. Setting this attribute to true will permit the Backup Manager to attempt restore even when a version mismatch suggests that the data are incompatible. Use with caution!

The default value of this attribute is false .

Must be a boolean value, either " true " or " false ".

This may also be a reference to a resource (in the form " @[ package :] type : name ") or theme attribute (in the form " ?[ package :][ type :] name ") containing a value of this type.

This corresponds to the global attribute resource symbol restoreAnyVersion .

Related Methods

Public Constructors

public BackupManager ( Context context)

Added in API level 8

Constructs a BackupManager object through which the application can communicate with the Android backup system.

Parameters
context The Context that was provided when one of your application's Activities was created.

Public Methods

public void dataChanged ()

Added in API level 8

Notifies the Android backup system that your application wishes to back up new changes to its data. A backup operation using your application's BackupAgent subclass will be scheduled when you call this method.

public static void dataChanged ( String packageName)

Added in API level 8

Convenience method for callers who need to indicate that some other package needs a backup pass. This can be useful in the case of groups of packages that share a uid.

This method requires that the application hold the "android.permission.BACKUP" permission if the package named in the argument does not run under the same uid as the caller.

Parameters
packageName The package name identifying the application to back up.

public int requestRestore ( RestoreObserver observer)

Added in API level 8

Restore the calling application from backup. The data will be restored from the current backup dataset if the application has stored data there, or from the dataset used during the last full device setup operation if the current backup dataset has no matching data. If no backup data exists for this application in either source, a nonzero value will be returned.

If this method returns zero (meaning success), the OS will attempt to retrieve a backed-up dataset from the remote transport, instantiate the application's backup agent, and pass the dataset to the agent's onRestore() method.

Parameters
observer The RestoreObserver to receive callbacks during the restore operation. This must not be null.
Returns
  • Zero on success; nonzero on error.