public class

BackupAgentHelper

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

Class Overview

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.

Summary

[Expand]
Inherited Constants
From class android.content.Context
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.
[Expand]
Inherited Methods
From class android.app.backup.BackupAgent
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object

Public Constructors

public BackupAgentHelper ()

Since: API Level 8

Public Methods

public void addHelper (String keyPrefix, BackupHelper helper)

Since: API Level 8

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 A string used to disambiguate the various helpers within this agent
helper A backup/restore helper object to be invoked during backup and restore operations.

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

Since: API Level 8

Run the backup process on each of the configured handlers.

Parameters
oldState 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 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 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

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

Since: API Level 8

Run the restore process on each of the configured handlers.

Parameters
data 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 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 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.
Throws
IOException