Added in API level 8

BackupAgentHelper

open class BackupAgentHelper : BackupAgent
kotlin.Any
   ↳ 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.

Summary

Inherited constants
Public constructors

Public methods
open Unit
addHelper(keyPrefix: String!, helper: BackupHelper!)

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

open Unit

Run the backup process on each of the configured handlers.

open Unit
onRestore(data: BackupDataInput!, appVersionCode: Int, newState: ParcelFileDescriptor!)

Run the restore process on each of the configured handlers.

Inherited functions

Public constructors

BackupAgentHelper

BackupAgentHelper()

Public methods

addHelper

Added in API level 8
open fun addHelper(
    keyPrefix: String!,
    helper: BackupHelper!
): Unit

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
open fun onBackup(
    oldState: ParcelFileDescriptor!,
    data: BackupDataOutput!,
    newState: ParcelFileDescriptor!
): Unit

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.

onRestore

Added in API level 8
open fun onRestore(
    data: BackupDataInput!,
    appVersionCode: Int,
    newState: ParcelFileDescriptor!
): Unit

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.