当前位置: 首页>>代码示例>>Java>>正文


Java BackupDataInput.skipEntityData方法代码示例

本文整理汇总了Java中android.app.backup.BackupDataInput.skipEntityData方法的典型用法代码示例。如果您正苦于以下问题:Java BackupDataInput.skipEntityData方法的具体用法?Java BackupDataInput.skipEntityData怎么用?Java BackupDataInput.skipEntityData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.backup.BackupDataInput的用法示例。


在下文中一共展示了BackupDataInput.skipEntityData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRestore

import android.app.backup.BackupDataInput; //导入方法依赖的package包/类
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
    ParcelFileDescriptor newState) throws IOException {
  Log.i(TAG, "Restoring from backup");
  while (data.readNextHeader()) {
    String key = data.getKey();
    Log.d(TAG, "Restoring entity " + key);
    if (key.equals(PREFERENCES_ENTITY)) {
      restorePreferences(data);
    } else {
      Log.e(TAG, "Found unknown backup entity: " + key);
      data.skipEntityData();
    }
  }
  Log.i(TAG, "Done restoring from backup");
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:17,代码来源:MyTracksBackupAgent.java

示例2: onRestore

import android.app.backup.BackupDataInput; //导入方法依赖的package包/类
/**
 * This application does not do any "live" restores of its own data,
 * so the only time a restore will happen is when the application is
 * installed.  This means that the activity itself is not going to
 * be running while we change its data out from under it.  That, in
 * turn, means that there is no need to send out any sort of notification
 * of the new data:  we only need to read the data from the stream
 * provided here, build the application's new data file, and then
 * write our new backup state blob that will be consulted at the next
 * backup operation.
 * 
 * <p>We don't bother checking the versionCode of the app who originated
 * the data because we have never revised the backup data format.  If
 * we had, the 'appVersionCode' parameter would tell us how we should
 * interpret the data we're about to read.
 */
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
        ParcelFileDescriptor newState) throws IOException {
    // We should only see one entity in the data stream, but the safest
    // way to consume it is using a while() loop
    while (data.readNextHeader()) {
        String key = data.getKey();
        int dataSize = data.getDataSize();

        if (APP_DATA_KEY.equals(key)) {
            // It's our saved data, a flattened chunk of data all in
            // one buffer.  Use some handy structured I/O classes to
            // extract it.
            byte[] dataBuf = new byte[dataSize];
            data.readEntityData(dataBuf, 0, dataSize);
            ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf);
            DataInputStream in = new DataInputStream(baStream);

            mFilling = in.readInt();
            mAddMayo = in.readBoolean();
            mAddTomato = in.readBoolean();

            // Now we are ready to construct the app's data file based
            // on the data we are restoring from.
            synchronized (BackupRestoreActivity.sDataLock) {
                RandomAccessFile file = new RandomAccessFile(mDataFile, "rw");
                file.setLength(0L);
                file.writeInt(mFilling);
                file.writeBoolean(mAddMayo);
                file.writeBoolean(mAddTomato);
            }
        } else {
            // Curious!  This entity is data under a key we do not
            // understand how to process.  Just skip it.
            data.skipEntityData();
        }
    }

    // The last thing to do is write the state blob that describes the
    // app's data as restored from backup.
    writeStateFile(newState);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:59,代码来源:ExampleAgent.java


注:本文中的android.app.backup.BackupDataInput.skipEntityData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。