Snapshot | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Inherited Constants | Methods | Inherited Methods | [Expand All]
public interface

# Snapshot

implements Parcelable Freezable<T>

com.google.android.gms.games.snapshot.Snapshot

Known Indirect Subclasses SnapshotEntity
SnapshotEntity | Data object representing the data for a saved game.

## Class Overview

Data interface for a representation of a saved game. This includes both the metadata and the actual game content.

## Summary

[Expand] Inherited Constants
From interface android.os.Parcelable
int | CONTENTS_FILE_DESCRIPTOR |
int | PARCELABLE_WRITE_RETURN_VALUE |

Public Methods
abstract Contents | getContents() Retrieve the `Contents` associated with this snapshot.
abstract SnapshotMetadata | getMetadata() Retrieves the metadata for this snapshot.
abstract boolean | modifyBytes(int dstOffset, byte[] content, int srcOffset, int count) Write the specified data into the snapshot.
abstract byte[] | readFully() Read the contents of a snapshot.
abstract boolean | writeBytes(byte[] content) Write the specified data into the snapshot.

[Expand] Inherited Methods
From interface android.os.Parcelable
abstract int | describeContents()
abstract void | writeToParcel(Parcel arg0, int arg1)
From interface com.google.android.gms.common.data.Freezable
abstract T | freeze() Freeze a volatile representation into an immutable representation.
abstract boolean | isDataValid() Check to see if this object is valid for use.

## Public Methods

#### public abstract Contents getContents ()

Retrieve the `Contents` associated with this snapshot. This object can be used to update the data of a snapshot. Note that this will return null if this snapshot was not obtained via `open(GoogleApiClient, SnapshotMetadata)`.

##### Returns

- The `Contents` for this snapshot, or null if the snapshot is not opened.

#### public abstract SnapshotMetadata getMetadata ()

Retrieves the metadata for this snapshot.

##### Returns

- The `SnapshotMetadata` associated with this snapshot.

#### public abstract boolean modifyBytes (int dstOffset, byte[] content, int srcOffset, int count)

Write the specified data into the snapshot. The contents of the snapshot will be replaced with the data provided in `content`. The data will be persisted on disk, but is not uploaded to the server until the snapshot is committed via `commitAndClose(GoogleApiClient, Snapshot, SnapshotMetadataChange)`.

Note that this form of the API does not necessarily overwrite the entire contents of the file. If you are writing less data than was previously stored in the snapshot, the excess data will remain. Use `writeBytes(byte[])` to fully overwrite the file.

If the snapshot was not opened via `open(GoogleApiClient, SnapshotMetadata)`, or if the contents have already been committed via `commitAndClose(GoogleApiClient, Snapshot, SnapshotMetadataChange)`, this method will throw an exception.

##### Parameters

dstOffset | Position in the snapshot file to start writing data to. 0 indicates the head of the file.
content | The data to write.
srcOffset | Position in content to start writing from.
count | Number of bytes from content to write to this snapshot.

##### Returns

- Whether or not the data was successfully written to disk.

#### public abstract byte[] readFully ()

Read the contents of a snapshot.

If this snapshot was not opened via `open(GoogleApiClient, SnapshotMetadata)`, or if the contents have already been committed via `commitAndClose(GoogleApiClient, Snapshot, SnapshotMetadataChange)` this method will throw an exception.

##### Returns

- The bytes of the snapshot contents.

#### public abstract boolean writeBytes (byte[] content)

Write the specified data into the snapshot. The contents of the snapshot will be replaced with the data provided in `content`. The data will be persisted on disk, but is not uploaded to the server until the snapshot is committed via `commitAndClose(GoogleApiClient, Snapshot, SnapshotMetadataChange)`.

Note that this form of the API will fully overwrite the contents of the file. No previous data will be retained. Use `modifyBytes(int, byte[], int, int)` to overwrite parts of the file.

If the snapshot was not opened via `open(GoogleApiClient, SnapshotMetadata)`, or if the contents have already been committed via `commitAndClose(GoogleApiClient, Snapshot, SnapshotMetadataChange)`, this method will throw an exception.

##### Parameters

content | The data to write.

##### Returns

- Whether or not the data was successfully written to disk.