BackupAgentHelper

public class BackupAgentHelper
extends BackupAgent

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.backup.BackupAgent
         ↳ android.app.backup.BackupAgentHelper


A convenient BackupAgent wrapper class that automatically manages heterogeneous data sets within the backup data, each identified by a unique key prefix. When processing a backup or restore operation, the BackupAgentHelper dispatches to one or more installed BackupHelper objects, each of which is responsible for a defined subset of the data being processed.

An application will typically extend this class in its own backup agent. Then, within the agent's onCreate() method, it will call addHelper() one or more times to install the handlers for each kind of data it wishes to manage within its backups.

The Android framework currently provides two predefined BackupHelper classes:

An application can also implement its own helper classes to work within the BackupAgentHelper framework. See the BackupHelper interface documentation for details.

Developer Guides

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

Summary

Inherited constants

Public constructors

BackupAgentHelper()

Public methods

void addHelper(String keyPrefix, BackupHelper helper)

Add a helper for a given data subset to the agent's configuration.

void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState)

Run the backup process on each of the configured handlers.

void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)

Run the restore process on each of the configured handlers.

Inherited methods

Public constructors

BackupAgentHelper

public BackupAgentHelper ()

Public methods

addHelper

Added in API level 8
public void addHelper (String keyPrefix, 
                BackupHelper helper)

Add a helper for a given data subset to the agent's configuration. Each helper must have a prefix string that is unique within this backup agent's set of helpers.

Parameters
keyPrefix String: A string used to disambiguate the various helpers within this agent

helper BackupHelper: A backup/restore helper object to be invoked during backup and restore operations.

onBackup

Added in API level 8
public void onBackup (ParcelFileDescriptor oldState, 
                BackupDataOutput data, 
                ParcelFileDescriptor newState)

Run the backup process on each of the configured handlers.

Parameters
oldState ParcelFileDescriptor: An open, read-only ParcelFileDescriptor pointing to the last backup state provided by the application. May be null, in which case no prior state is being provided and the application should perform a full backup.

data BackupDataOutput: A structured wrapper around an open, read/write file descriptor pointing to the backup data destination. Typically the application will use backup helper classes to write to this file.

newState ParcelFileDescriptor: An open, read/write ParcelFileDescriptor pointing to an empty file. The application should record the final backup state here after writing the requested data to the data output stream.

Throws
IOException

onRestore

Added in API level 8
public void onRestore (BackupDataInput data, 
                int appVersionCode, 
                ParcelFileDescriptor newState)

Run the restore process on each of the configured handlers.

Parameters
data BackupDataInput: A structured wrapper around an open, read-only file descriptor pointing to a full snapshot of the application's data. The application should consume every entity represented in this data stream.

appVersionCode int: The value of the android:versionCode manifest attribute, from the application that backed up this particular data set. This makes it possible for an application's agent to distinguish among any possible older data versions when asked to perform the restore operation.

newState ParcelFileDescriptor: An open, read/write ParcelFileDescriptor pointing to an empty file. The application should record the final backup state here after restoring its data from the data stream. When a full-backup dataset is being restored, this will be null.

Throws
IOException