Code example for BackupDataOutput

Methods: writeEntityData, writeEntityHeader

0
 
  private void backupPreferences(BackupDataOutput data,
      SharedPreferences preferences) throws IOException {
    PreferenceBackupHelper preferenceDumper = createPreferenceBackupHelper();
    byte[] dumpedContents = preferenceDumper.exportPreferences(preferences);
    data.writeEntityHeader(PREFERENCES_ENTITY, dumpedContents.length);
    data.writeEntityData(dumpedContents, dumpedContents.length);
  } 
 
  protected PreferenceBackupHelper createPreferenceBackupHelper() { 
    return new PreferenceBackupHelper(); 
  } 
 
  @Override 
  public void onRestore(BackupDataInput data, int appVersionCode,
      ParcelFileDescriptor newState) throws IOException {
    Log.i(Constants.TAG, "Restoring from backup");
    while (data.readNextHeader()) {
      String key = data.getKey();
      Log.d(Constants.TAG, "Restoring entity " + key);
      if (key.equals(PREFERENCES_ENTITY)) {