FileDocCategorySizeDatePackage
BackupAgentHelper.javaAPI DocAndroid 5.1 API3810Thu Mar 12 22:22:10 GMT 2015android.app.backup

BackupAgentHelper

public class BackupAgentHelper extends BackupAgent
A convenient {@link 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 {@link 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 {@link BackupAgent#onCreate() onCreate()} method, it will call {@link #addHelper(String, BackupHelper) 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 {@link BackupHelper} classes:

  • {@link FileBackupHelper} - Manages the backup and restore of entire files within an application's data directory hierarchy.
  • {@link SharedPreferencesBackupHelper} - Manages the backup and restore of an application's {@link android.content.SharedPreferences} data.

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

Developer Guides

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

see
BackupHelper
see
FileBackupHelper
see
SharedPreferencesBackupHelper

Fields Summary
static final String
TAG
BackupHelperDispatcher
mDispatcher
Constructors Summary
Methods Summary
public voidaddHelper(java.lang.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.

param
keyPrefix A string used to disambiguate the various helpers within this agent
param
helper A backup/restore helper object to be invoked during backup and restore operations.

        mDispatcher.addHelper(keyPrefix, helper);
    
public BackupHelperDispatchergetDispatcher()

hide

        return mDispatcher;
    
public voidonBackup(android.os.ParcelFileDescriptor oldState, BackupDataOutput data, android.os.ParcelFileDescriptor newState)
Run the backup process on each of the configured handlers.


                   
    
         
                 
        mDispatcher.performBackup(oldState, data, newState);
    
public voidonRestore(BackupDataInput data, int appVersionCode, android.os.ParcelFileDescriptor newState)
Run the restore process on each of the configured handlers.

        mDispatcher.performRestore(data, appVersionCode, newState);