I am using the Google Backup API for SharedPreferences
as described here:
http://developer.android.com/guide/topics/data/backup.html#RequestingRestore
When using bmgr, as described here: http://developer.android.com/tools/help/bmgr.html
I do get the log messages for onRestore an onBackup methods, but in onRestore I get this line:
06-06 11:24:16.546: D/backup_data(24615): SKIP_PADDING FAILED at line 332
The only reference for it is here: https://github.com/comex/frash/blob/master/utils/utils/BackupData.cpp
And no input is read.
My Helper class:
public class NoteBackupAgent extends BackupAgentHelper {
public static final Object[] DATA_LOCK = new Object[0];
private static final String PREFS_BACKUP_KEY = Const.ENTRY_PREFS;
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
Log.d(toString(), "########### onBackup() " + oldState.getStatSize());
synchronized (DATA_LOCK) {
super.onBackup(oldState, data, newState);
}
}
@Override
public void onCreate() {
SharedPreferencesBackupHelper preferencesHelper = new SharedPreferencesBackupHelper(this,
getPackageName() + "_preferences");
Toast.makeText(getApplicationContext(), "onCreate", Toast.LENGTH_LONG).show();
addHelper(PREFS_BACKUP_KEY, preferencesHelper);
}
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
throws IOException {
synchronized (DATA_LOCK) {
//super.onRestore(data, appVersionCode, newState);
// There should be only one entity, but the safest
// way to consume it is using a while loop
StringBuilder total = new StringBuilder();
while (data.readNextHeader()) {
String key = data.getKey();
int dataSize = data.getDataSize();
// If the key is ours (for saving top score). Note this key was used when
// we wrote the backup entity header
if (PREFS_BACKUP_KEY.equals(key)) {
// Create an input stream for the BackupDataInput
byte[] dataBuf = new byte[dataSize];
data.readEntityData(dataBuf, 0, dataSize);
ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf);
DataInputStream in = new DataInputStream(baStream);
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
Log.d(toString(), "########## data " + total);
} else {
data.skipEntityData();
}
}
Log.d(toString(), "########## onRestore()" + total.toString());
}
}
}