Quicknav Quicknav
Links

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

Android Sites

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

close

- - Get Started
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
    - Get the SDK
  - Google Services
- - Google Play
  - Publishing
  - Promoting
  - App Quality
  - Spotlight
  - Open Distribution

## Results

Loading...
Summary: Nested Classes | Fields | Methods | Inherited Methods | [Expand All]
public final class

# AppStateManager

extends Object

java.lang.Object
↳ | com.google.android.gms.appstate.AppStateManager

## Class Overview

Main public API entry point for the AppState APIs.

## Summary

Nested Classes
interface | AppStateManager.StateConflictResult | Result retrieved from `AppStateManager.StateResult` when a conflict is detected while loading app state.
interface | AppStateManager.StateDeletedResult | Result delivered when app state data has been deleted.
interface | AppStateManager.StateListResult | Result delivered when app state data has been loaded.
interface | AppStateManager.StateLoadedResult | Result retrieved from `AppStateManager.StateResult` when app state data has been loaded successfully.
interface | AppStateManager.StateResult | Result of an operation that could potentially generate a state conflict.

Fields
public static final Api | API | Token to pass to `addApi(Api)` to enable AppState features.
public static final Scope | SCOPE_APP_STATE | Scope for using the App State service.

Public Methods
static PendingResult<AppStateManager.StateDeletedResult> | delete(GoogleApiClient googleApiClient, int stateKey) Delete the state data for the current app.
static int | getMaxNumKeys(GoogleApiClient googleApiClient) Gets the maximum number of keys that an app can store data in simultaneously.
static int | getMaxStateSize(GoogleApiClient googleApiClient) Gets the maximum app state size per state key in bytes.
static PendingResult<AppStateManager.StateListResult> | list(GoogleApiClient googleApiClient) Asynchronously lists all the saved states for the current app.
static PendingResult<AppStateManager.StateResult> | load(GoogleApiClient googleApiClient, int stateKey) Asynchronously loads saved state for the current app.
static PendingResult<AppStateManager.StateResult> | resolve(GoogleApiClient googleApiClient, int stateKey, String resolvedVersion, byte[] resolvedData) Resolve a previously detected conflict in app state data.
static PendingResult<Status> | signOut(GoogleApiClient googleApiClient) Asynchronously signs the current user out.
static void | update(GoogleApiClient googleApiClient, int stateKey, byte[] data) Updates app state for the current app.
static PendingResult<AppStateManager.StateResult> | updateImmediate(GoogleApiClient googleApiClient, int stateKey, byte[] data) Updates app state for the current app.

[Expand] Inherited Methods

From class java.lang.Object

Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)

## Fields

#### public static final Api API

Token to pass to `addApi(Api)` to enable AppState features.

#### public static final Scope SCOPE_APP_STATE

Scope for using the App State service.

## Public Methods

#### public static PendingResult<AppStateManager.StateDeletedResult> delete (GoogleApiClient googleApiClient, int stateKey)

Delete the state data for the current app. This method will delete all data associated with the provided key, as well as removing the key itself.

Note that this API is not version safe. This means that it is possible to accidentally delete a user's data using this API. For a version safe alternative, consider using `update(GoogleApiClient, int, byte[])` with `null` data instead.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.
stateKey | The key to clear data for. Must be a non-negative integer less than `getMaxNumKeys(GoogleApiClient)`.

##### Returns

- `PendingResult` to access the data when available.

#### public static int getMaxNumKeys (GoogleApiClient googleApiClient)

Gets the maximum number of keys that an app can store data in simultaneously.

If the service cannot be reached for some reason, this will return `STATUS_CLIENT_RECONNECT_REQUIRED`. In this case, no further operations should be attempted until after the client has reconnected.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.

##### Returns

- The maximum number of keys that an app can use for data.

#### public static int getMaxStateSize (GoogleApiClient googleApiClient)

Gets the maximum app state size per state key in bytes. Guaranteed to be at least 256 KB. May increase in the future.

If the service cannot be reached for some reason, this will return `STATUS_CLIENT_RECONNECT_REQUIRED`. In this case, no further operations should be attempted until after the client has reconnected.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.

##### Returns

- The maximum state size that can be stored with a given state key in bytes.

#### public static PendingResult<AppStateManager.StateListResult> list (GoogleApiClient googleApiClient)

Asynchronously lists all the saved states for the current app.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.

##### Returns

- `PendingResult` to access the data when available.

#### public static PendingResult<AppStateManager.StateResult> load (GoogleApiClient googleApiClient, int stateKey)

Asynchronously loads saved state for the current app.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.
stateKey | The key to load data for. Must be a non-negative integer less than `getMaxNumKeys(GoogleApiClient)`.

##### Returns

- `PendingResult` to access the data when available.

#### public static PendingResult<AppStateManager.StateResult> resolve (GoogleApiClient googleApiClient, int stateKey, String resolvedVersion, byte[] resolvedData)

Resolve a previously detected conflict in app state data. Note that it is still possible to receive a conflict callback after this call. This will occur if data on the server continues to change. In this case, resolution should be retried until a successful status is returned.

The value of `resolvedVersion` passed here must correspond to the value provided in the `onStateConflict(int, String, byte[], byte[])` call.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.
stateKey | The key to resolve data for. Must be a non-negative integer less than `getMaxNumKeys(GoogleApiClient)`.
resolvedVersion | Version code from previous `onStateConflict` call.
resolvedData | Data to submit as the current data. `null` is a valid value here. May be a maximum of `getMaxStateSize(GoogleApiClient)` bytes.

##### Returns

- `PendingResult` to access the data when available.

#### public static PendingResult<Status> signOut (GoogleApiClient googleApiClient)

Asynchronously signs the current user out.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.

##### Returns

- `PendingResult` to access the data when available.

#### public static void update (GoogleApiClient googleApiClient, int stateKey, byte[] data)

Updates app state for the current app. The data provided here is developer-specified and can be in any format appropriate for the app. This method updates the local copy of the app state and syncs the changes to the server. If the local data conflicts with the data on the server, this will be indicated the next time you call `load(GoogleApiClient, int)`.

This is the fire-and-forget form of the API. Use this form if you don't need to know the results of the operation immediately. For most applications, this will be the preferred API to use. See `updateImmediate(GoogleApiClient, int, byte[])` if you need the results delivered to your application.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.
stateKey | The key to update data for. Must be a non-negative integer less than `getMaxNumKeys(GoogleApiClient)`.
data | The data to store. May be a maximum of `getMaxStateSize(GoogleApiClient)` bytes.

#### public static PendingResult<AppStateManager.StateResult> updateImmediate (GoogleApiClient googleApiClient, int stateKey, byte[] data)

Updates app state for the current app. The data provided here is developer-specified and can be in any format appropriate for the app. This method will attempt to update the data on the server immediately. The results of this operation will be returned via a PendingResult.

Required API: `API`
Required Scopes: `SCOPE_APP_STATE`

##### Parameters

googleApiClient | The `GoogleApiClient` to service the call.
stateKey | The key to update data for. Must be a non-negative integer less than `getMaxNumKeys(GoogleApiClient)`.
data | The data to store. May be a maximum of `getMaxStateSize(GoogleApiClient)` bytes.

##### Returns

- `PendingResult` to access the data when available.