See Also: BackupAgent Members
Provides the central interface between an application and Android's data backup infrastructure. An application that wishes to participate in the backup and restore mechanism will declare a subclass of Android.App.Backup.BackupAgent, implement the BackupAgent.OnBackup(Android.OS.ParcelFileDescriptor, Android.App.Backup.BackupDataOutput, Android.App.Backup.BackupDataOutput) and BackupAgent.OnRestore(BackupDataInput, System.Int32, System.Int32) methods, and provide the name of its backup agent class in its AndroidManifest.xml file via the <application> tag's android:backupAgent attribute.
For more information about using BackupAgent, read the Data Backup developer guide.
When the application makes changes to data that it wishes to keep backed up, it should call the BackupManager.DataChanged method. This notifies the Android Backup Manager that the application needs an opportunity to update its backup image. The Backup Manager, in turn, schedules a backup pass to be performed at an opportune time.
Restore operations are typically performed only when applications are first installed on a device. At that time, the operating system checks to see whether there is a previously-saved data set available for the application being installed, and if so, begins an immediate restore pass to deliver the backup data as part of the installation process.
When a backup or restore pass is run, the application's process is launched (if not already running), the manifest-declared backup agent class (in the android:backupAgent attribute) is instantiated within that process, and the agent's BackupAgent.OnCreate method is invoked. This prepares the agent instance to run the actual backup or restore logic. At this point the agent's BackupAgent.OnBackup(Android.OS.ParcelFileDescriptor, Android.App.Backup.BackupDataOutput, Android.App.Backup.BackupDataOutput) or BackupAgent.OnRestore(BackupDataInput, System.Int32, System.Int32) method will be invoked as appropriate for the operation being performed.
A backup data set consists of one or more "entities," flattened binary data records that are each identified with a key string unique within the data set. Adding a record to the active data set or updating an existing record is done by simply writing new entity data under the desired key. Deleting an entity from the data set is done by writing an entity under that key with header specifying a negative data size, and no actual entity data.
Helper Classes
An extensible agent based on convenient helper classes is available in Android.App.Backup.BackupAgentHelper. That class is particularly suited to handling of simple file or Android.Content.ISharedPreferences backup and restore.