Android.App.Backup.SharedPreferencesBackupHelper Class
A helper class that can be used in conjunction with Android.App.Backup.BackupAgentHelper to manage the backup of Android.Content.ISharedPreferences.

See Also: SharedPreferencesBackupHelper Members

Syntax

[Android.Runtime.Register("android/app/backup/SharedPreferencesBackupHelper", DoNotGenerateAcw=true)]
public class SharedPreferencesBackupHelper : FileBackupHelperBase, IBackupHelper, IDisposable

Remarks

A helper class that can be used in conjunction with Android.App.Backup.BackupAgentHelper to manage the backup of Android.Content.ISharedPreferences. Whenever a backup is performed, it will back up all named shared preferences that have changed since the last backup operation.

To use this class, the application's backup agent class should extend Android.App.Backup.BackupAgentHelper. Then, in the agent's BackupAgent.OnCreate method, an instance of this class should be allocated and installed as a backup/restore handler within the BackupAgentHelper framework. For example, an agent supporting backup and restore for an application with two groups of Android.Content.ISharedPreferences data might look something like this:

java Example

 import android.app.backup.BackupAgentHelper;
 import android.app.backup.SharedPreferencesBackupHelper;

 public class MyBackupAgent extends BackupAgentHelper {
     // The names of the SharedPreferences groups that the application maintains.  These
     // are the same strings that are passed to getSharedPreferences(String, int).
     static final String PREFS_DISPLAY = "displayprefs";
     static final String PREFS_SCORES = "highscores";

     // An arbitrary string used within the BackupAgentHelper implementation to
     // identify the SharedPreferenceBackupHelper's data.
     static final String MY_PREFS_BACKUP_KEY = "myprefs";

     // Simply allocate a helper and install it
     void onCreate() {
         SharedPreferencesBackupHelper helper =
                 new SharedPreferencesBackupHelper(this, PREFS_DISPLAY, PREFS_SCORES);
         addHelper(MY_PREFS_BACKUP_KEY, helper);
     }
 }

No further implementation is needed; the Android.App.Backup.BackupAgentHelper mechanism automatically dispatches the BackupAgent.OnBackup(Android.OS.ParcelFileDescriptor, Android.App.Backup.BackupDataOutput, Android.App.Backup.BackupDataOutput) and BackupAgent.OnRestore(BackupDataInput, System.Int32, System.Int32) callbacks to the SharedPreferencesBackupHelper as appropriate.

[Android Documentation]

Requirements

Namespace: Android.App.Backup
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 8