Most visited

Recently visited

Added in API level 8

BackupAgentHelper

public class BackupAgentHelper
extends BackupAgent

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


一种便捷的BackupAgent包装类,可自动管理备份数据中的异构数据集,每个数据集均由唯一键前缀标识。 当处理一个备份或恢复操作中,BackupAgentHelper分派给一个或多个安装BackupHelper对象,正在处理一个定义的数据的子集的每一个负责。

应用程序通常会在自己的备份代理中扩展此类。 然后,在代理的onCreate()方法中,它将调用addHelper()一次或多次为其希望在其备份中管理的每种数据安装处理程序。

Android框架目前提供两个预定义的 BackupHelper类:

应用程序也可以实现自己的帮助器类以在BackupAgentHelper框架内工作。 有关详细信息,请参阅BackupHelper接口文档。

Developer Guides

有关使用BackupAgentHelper的更多信息,请阅读 Data Backup开发人员指南。

也可以看看:

Summary

Inherited constants

From class android.app.backup.BackupAgent
From class android.content.Context

Public constructors

BackupAgentHelper()

Public methods

void addHelper(String keyPrefix, BackupHelper helper)

将给定数据子集的助手添加到代理的配置中。

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

在每个配置的处理程序上运行备份过程。

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

在每个配置的处理程序上运行恢复过程。

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

BackupAgentHelper

Added in API level 8
BackupAgentHelper ()

Public methods

addHelper

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

将给定数据子集的助手添加到代理的配置中。 每个助手必须有一个前缀字符串,该前缀字符串在此备份代理的助手集中是唯一的。

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
void onBackup (ParcelFileDescriptor oldState, 
                BackupDataOutput data, 
                ParcelFileDescriptor newState)

在每个配置的处理程序上运行备份过程。

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
void onRestore (BackupDataInput data, 
                int appVersionCode, 
                ParcelFileDescriptor newState)

在每个配置的处理程序上运行恢复过程。

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

Hooray!