/**@class android.app.backup.SharedPreferencesBackupHelper
implements android.app.backup.BackupHelper
@extends android.app.backup.FileBackupHelperBase
A helper class that can be used in conjunction with
{@link android.app.backup.BackupAgentHelper} to manage the backup of
{@link android.content.SharedPreferences}. Whenever a backup is performed, it
will back up all named shared preferences that have changed since the last
backup operation.
<p>
To use this class, the application's backup agent class should extend
{@link android.app.backup.BackupAgentHelper}. Then, in the agent's
{@link android.app.backup.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 {@link android.content.SharedPreferences}
data might look something like this:
<pre>
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 {@link Context#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";
// Allocate a helper and install it.
public void onCreate() {
SharedPreferencesBackupHelper helper =
new SharedPreferencesBackupHelper(this, PREFS_DISPLAY, PREFS_SCORES);
addHelper(MY_PREFS_BACKUP_KEY, helper);
}
}</pre>
<p>
No further implementation is needed; the {@link android.app.backup.BackupAgentHelper} mechanism automatically
dispatches the
{@link android.app.backup.BackupAgent#onBackup(android.os.ParcelFileDescriptor, BackupDataOutput, android.os.ParcelFileDescriptor) android.app.backup.BackupAgent.onBackup()}
and
{@link android.app.backup.BackupAgent#onRestore(BackupDataInput, int, android.os.ParcelFileDescriptor) android.app.backup.BackupAgent.onRestore()}
callbacks to the SharedPreferencesBackupHelper as appropriate.
*/
var SharedPreferencesBackupHelper = {
/**Backs up the configured {@link android.content.SharedPreferences} groups.
*/
performBackup : function( ) {},
/**Restores one entity from the restore data stream to its proper shared
preferences file store.
*/
restoreEntity : function( ) {},
};