Added in API level 8
BackupDataInput
public
class
BackupDataInput
extends Object
| java.lang.Object | |
| ↳ | android.app.backup.BackupDataInput |
Provides the structured interface through which a BackupAgent reads
information from the backup data set, via its
onRestore()
method. The data is presented as a set of "entities," each
representing one named record as previously stored by the agent's
onBackup() implementation. An entity is composed of a descriptive header plus a
byte array that holds the raw data saved in the remote backup.
The agent must consume every entity in the data stream, otherwise the restored state of the application will be incomplete.
Example
A typical
onRestore() implementation might be structured something like this:
public void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState) {
while (data.readNextHeader()) {
String key = data.getKey();
int dataSize = data.getDataSize();
if (key.equals(MY_BACKUP_KEY_ONE)) {
// process this kind of record here
byte[] buffer = new byte[dataSize];
data.readEntityData(buffer, 0, dataSize); // reads the entire entity at once
// now 'buffer' holds the raw data and can be processed however
// the agent wishes
processBackupKeyOne(buffer);
} else if (key.equals(MY_BACKUP_KEY_TO_IGNORE) {
// a key we recognize but wish to discard
data.skipEntityData();
} // ... etc.
}
}Summary
Public methods | |
|---|---|
int
|
|