question: @ Override public void onBackup ( ParcelFileDescriptor oldState , BackupDataOutput data , ParcelFileDescriptor newState ) throws IOException { synchronized ( HugeBackupActivity . sDataLock ) { RandomAccessFile file = new RandomAccessFile ( mDataFile , "r" ) ; mFilling = file . readInt ( ) ; mAddMayo = file . readBoolean ( ) ; mAddTomato = file . readBoolean ( ) ; } boolean doBackup = ( oldState == null ) ; if ( ! doBackup ) { doBackup = compareStateFile ( oldState ) ; } if ( doBackup ) { ByteArrayOutputStream bufStream = new ByteArrayOutputStream ( ) ; DataOutputStream outWriter = new DataOutputStream ( bufStream ) ; outWriter . writeInt ( mFilling ) ; outWriter . writeBoolean ( mAddMayo ) ; outWriter . writeBoolean ( mAddTomato ) ; byte [ ] buffer = bufStream . toByteArray ( ) ; int len = buffer . length ; data . writeEntityHeader ( APP_DATA_KEY , len ) ; data . writeEntityData ( buffer , len ) ; final int MEGABYTE = 1024 * 1024 ; final int NUM_MEGS = 20 ; buffer = new byte [ MEGABYTE ] ; data . writeEntityHeader ( HUGE_DATA_KEY , NUM_MEGS * MEGABYTE ) ; for ( int i = 0 ; i < NUM_MEGS ; i ++ ) { data . writeEntityData ( buffer , MEGABYTE ) ; } } writeStateFile ( newState ) ; }
target:  The set of data backed up by this application is very small: just two booleans and an integer.  With such a simple dataset, it's easiest to simply store a copy of the backed-up data as the state blob describing the last dataset backed up.  The state file contents can be anything; it is private to the agent class, and is never stored off-device. <p>One thing that an application may wish to do is tag the state blob contents with a version number.  This is so that if the application is upgraded, the next time it attempts to do a backup, it can detect that the last backup operation was performed by an older version of the agent, and might therefore require different handling.