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 | Constants | Methods | Inherited Methods | [Expand All]
public final class

# AppStateClient

extends Object
implements GooglePlayServicesClient

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

This class is deprecated.
See `AppStateManager` and `GoogleApiClient`.

## Class Overview

Main public API entry point for the AppState client.

## Summary

Nested Classes
class | AppStateClient.Builder | This class is deprecated. See `GoogleApiClient.Builder`.

Constants
int | STATUS_CLIENT_RECONNECT_REQUIRED | The AppStateClient is in an inconsistent state and must reconnect to the service to resolve the issue.
int | STATUS_DEVELOPER_ERROR | Your application is incorrectly configured.
int | STATUS_INTERNAL_ERROR | An unspecified error occurred; no more specific information is available.
int | STATUS_NETWORK_ERROR_NO_DATA | A network error occurred while attempting to retrieve fresh data, and no data was available locally.
int | STATUS_NETWORK_ERROR_OPERATION_DEFERRED | A network error occurred while attempting to modify data, but the data was successfully modified locally and will be updated on the network the next time the device is able to sync.
int | STATUS_NETWORK_ERROR_OPERATION_FAILED | A network error occurred while attempting to perform an operation that requires network access.
int | STATUS_NETWORK_ERROR_STALE_DATA | A network error occurred while attempting to retrieve fresh data, but some locally cached data was available.
int | STATUS_OK | The operation was successful.
int | STATUS_STATE_KEY_LIMIT_EXCEEDED | The application already has data in the maximum number of keys (data slots) and is attempting to create a new one.
int | STATUS_STATE_KEY_NOT_FOUND | The requested state key was not found.
int | STATUS_WRITE_OUT_OF_DATE_VERSION | A version conflict was detected.
int | STATUS_WRITE_SIZE_EXCEEDED | A write request was submitted which contained too much data for the server.

Public Methods
void | connect() This method is deprecated. See `disconnect()`.
void | deleteState(OnStateDeletedListener listener, int stateKey) This method is deprecated. See `delete(GoogleApiClient, int)`.
void | disconnect() This method is deprecated. See `disconnect()`.
int | getMaxNumKeys() This method is deprecated. See `getMaxNumKeys(GoogleApiClient)`.
int | getMaxStateSize() This method is deprecated. See `getMaxStateSize(GoogleApiClient)`.
boolean | isConnected() This method is deprecated. See `isConnected()`.
boolean | isConnecting() This method is deprecated. See `isConnecting()`.
boolean | isConnectionCallbacksRegistered(GooglePlayServicesClient.ConnectionCallbacks listener) This method is deprecated. See `isConnectionCallbacksRegistered(GoogleApiClient.ConnectionCallbacks)`.
boolean | isConnectionFailedListenerRegistered(GooglePlayServicesClient.OnConnectionFailedListener listener) This method is deprecated. See `isConnectionFailedListenerRegistered(GoogleApiClient.OnConnectionFailedListener)`.
void | listStates(OnStateListLoadedListener listener) This method is deprecated. See `list(GoogleApiClient)`.
void | loadState(OnStateLoadedListener listener, int stateKey) This method is deprecated. See `load(GoogleApiClient, int)`.
void | reconnect() This method is deprecated. See `reconnect()`
void | registerConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks listener) This method is deprecated. See `registerConnectionCallbacks(GoogleApiClient.ConnectionCallbacks)`.
void | registerConnectionFailedListener(GooglePlayServicesClient.OnConnectionFailedListener listener) This method is deprecated. See `registerConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener)`.
void | resolveState(OnStateLoadedListener listener, int stateKey, String resolvedVersion, byte[] resolvedData) This method is deprecated. See `resolve(GoogleApiClient, int, String, byte[])`.
void | signOut(OnSignOutCompleteListener listener) This method is deprecated. See `signOut(GoogleApiClient)`.
void | signOut() This method is deprecated. See `signOut(GoogleApiClient)`.
void | unregisterConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks listener) This method is deprecated. See `unregisterConnectionCallbacks(GoogleApiClient.ConnectionCallbacks)`.
void | unregisterConnectionFailedListener(GooglePlayServicesClient.OnConnectionFailedListener listener) This method is deprecated. See `unregisterConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener)`.
void | updateState(int stateKey, byte[] data) This method is deprecated. See `update(GoogleApiClient, int, byte[])`.
void | updateStateImmediate(OnStateLoadedListener listener, int stateKey, byte[] data) This method is deprecated. See `updateImmediate(GoogleApiClient, int, byte[])`.

[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)

From interface com.google.android.gms.common.GooglePlayServicesClient

abstract void | connect() Connects the client to Google Play services.
abstract void | disconnect() Closes the connection to Google Play services.
abstract boolean | isConnected() Checks if the client is currently connected to the service, so that requests to other methods will succeed.
abstract boolean | isConnecting() Checks if the client is attempting to connect to the service.
abstract boolean | isConnectionCallbacksRegistered(GooglePlayServicesClient.ConnectionCallbacks listener) Returns true if the specified listener is currently registered to receive connection events.
abstract boolean | isConnectionFailedListenerRegistered(GooglePlayServicesClient.OnConnectionFailedListener listener) Returns true if the specified listener is currently registered to receive connection failed events.
abstract void | registerConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks listener) Registers a listener to receive connection events from this `GooglePlayServicesClient`.
abstract void | registerConnectionFailedListener(GooglePlayServicesClient.OnConnectionFailedListener listener) Registers a listener to receive connection failed events from this `GooglePlayServicesClient`.
abstract void | unregisterConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks listener) Removes a connection listener from this `GooglePlayServicesClient`.
abstract void | unregisterConnectionFailedListener(GooglePlayServicesClient.OnConnectionFailedListener listener) Removes a connection failed listener from the `GooglePlayServicesClient`.

## Constants

#### public static final int STATUS_CLIENT_RECONNECT_REQUIRED

The AppStateClient is in an inconsistent state and must reconnect to the service to resolve the issue. Further calls to the service using the current connection are unlikely to succeed.

Constant Value: 2 (0x00000002)

#### public static final int STATUS_DEVELOPER_ERROR

Your application is incorrectly configured. This is a hard error, since retrying will not fix this.

Constant Value: 7 (0x00000007)

#### public static final int STATUS_INTERNAL_ERROR

An unspecified error occurred; no more specific information is available. The device logs may provide additional data.

Constant Value: 1 (0x00000001)

#### public static final int STATUS_NETWORK_ERROR_NO_DATA

A network error occurred while attempting to retrieve fresh data, and no data was available locally.

Constant Value: 4 (0x00000004)

#### public static final int STATUS_NETWORK_ERROR_OPERATION_DEFERRED

A network error occurred while attempting to modify data, but the data was successfully modified locally and will be updated on the network the next time the device is able to sync.

Constant Value: 5 (0x00000005)

#### public static final int STATUS_NETWORK_ERROR_OPERATION_FAILED

A network error occurred while attempting to perform an operation that requires network access. The operation may be retried later.

Constant Value: 6 (0x00000006)

#### public static final int STATUS_NETWORK_ERROR_STALE_DATA

A network error occurred while attempting to retrieve fresh data, but some locally cached data was available. The data returned may be stale and/or incomplete.

Constant Value: 3 (0x00000003)

#### public static final int STATUS_OK

The operation was successful.

Constant Value: 0 (0x00000000)

#### public static final int STATUS_STATE_KEY_LIMIT_EXCEEDED

The application already has data in the maximum number of keys (data slots) and is attempting to create a new one. This is a hard error. Subsequent writes to this same key will only succeed after some number of keys have been deleted.

Constant Value: 2003 (0x000007d3)

#### public static final int STATUS_STATE_KEY_NOT_FOUND

The requested state key was not found. This means that the server did not have data for us when we successfully made a network request.

Constant Value: 2002 (0x000007d2)

#### public static final int STATUS_WRITE_OUT_OF_DATE_VERSION

A version conflict was detected. This means that we have a local version of the data which is out of sync with the server.

Constant Value: 2000 (0x000007d0)

#### public static final int STATUS_WRITE_SIZE_EXCEEDED

A write request was submitted which contained too much data for the server. This should only occur if we change the app state size restrictions, or if someone is modifying their database directly.

Constant Value: 2001 (0x000007d1)

## Public Methods

#### public void connect ()

This method is deprecated.
See `disconnect()`.

Connect to the app state service. This method will return immediately, and `onConnected(Bundle)` will be called if the connection is successful.

##### See Also

- `connect()`

#### public void deleteState (OnStateDeletedListener listener, int stateKey)

This method is deprecated.
See `delete(GoogleApiClient, int)`.

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 `updateState(int, byte[])` with `null` data instead.

##### Parameters

listener | The listener that is called when the load is complete. This listener is required to be non-null. The listener is called on the main thread.
stateKey | The key to clear data for. Must be a non-negative integer less than `getMaxNumKeys()`.

#### public void disconnect ()

This method is deprecated.
See `disconnect()`.

Closes the connection to Google Play services. No calls can be made on this object after calling this method.

#### public int getMaxNumKeys ()

This method is deprecated.
See `getMaxNumKeys(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.

##### Returns

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

#### public int getMaxStateSize ()

This method is deprecated.
See `getMaxStateSize(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.

##### Returns

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

#### public boolean isConnected ()

This method is deprecated.
See `isConnected()`.

Checks if the client is currently connected to the service, so that requests to other methods will succeed. Applications should guard client actions caused by the user with a call to this method.

##### Returns

- true if the client is connected to the service.

#### public boolean isConnecting ()

This method is deprecated.
See `isConnecting()`.

Checks if the client is attempting to connect to the service.

##### Returns

- true if the client is attempting to connect to the service.

#### public boolean isConnectionCallbacksRegistered (GooglePlayServicesClient.ConnectionCallbacks listener)

This method is deprecated.
See `isConnectionCallbacksRegistered(GoogleApiClient.ConnectionCallbacks)`.

Returns true if the specified listener is currently registered to receive connection events.

##### Parameters

listener | The listener to check for.

##### Returns

- true if the specified listener is currently registered to receive connection events.

#### public boolean isConnectionFailedListenerRegistered (GooglePlayServicesClient.OnConnectionFailedListener listener)

This method is deprecated.
See `isConnectionFailedListenerRegistered(GoogleApiClient.OnConnectionFailedListener)`.

Returns true if the specified listener is currently registered to receive connection failed events.

##### Parameters

listener | The listener to check for.

##### Returns

- true if the specified listener is currently registered to receive connection failed events.

#### public void listStates (OnStateListLoadedListener listener)

This method is deprecated.
See `list(GoogleApiClient)`.

Asynchronously lists all the saved states for the current app.

The result is delivered to the given listener on the main thread. If `disconnect()` is called before the result is ready it will not be delivered.

##### Parameters

listener | The listener that is called when the load is complete. This listener is required to be non-null. The listener is called on the main thread.

#### public void loadState (OnStateLoadedListener listener, int stateKey)

This method is deprecated.
See `load(GoogleApiClient, int)`.

Asynchronously loads saved state for the current app.

The result is delivered to the given listener on the main thread. If `disconnect()` is called before the result is ready it will not be delivered.

##### Parameters

listener | The listener that is called when the load is complete. This listener is required to be non-null. The listener is called on the main thread.
stateKey | The key to load data for. Must be a non-negative integer less than `getMaxNumKeys()`.

#### public void reconnect ()

This method is deprecated.
See `reconnect()`

Closes the current connection to Google Play services and creates a new connection.

This method closes the current connection then returns immediately and reconnects to the service in the background.

This method will call `onDisconnected()` followed by either `onConnected(Bundle)` if the connection is successful or `onConnectionFailed(ConnectionResult)` on a failure.

##### See Also

- `connect()`
- `disconnect()`
- `connect()`

#### public void registerConnectionCallbacks (GooglePlayServicesClient.ConnectionCallbacks listener)

This method is deprecated.
See `registerConnectionCallbacks(GoogleApiClient.ConnectionCallbacks)`.

Registers a listener to receive connection events from this `GooglePlayServicesClient`. If the service is already connected, the listener's `onConnected(Bundle)` method will be called immediately. Applications should balance calls to this method with calls to `unregisterConnectionCallbacks(ConnectionCallbacks)` to avoid leaking resources.

If the specified listener is already registered to receive connection events, this method will not add a duplicate entry for the same listener, but will still call the listener's `onConnected(Bundle)` method if currently connected.

Note that the order of messages received here may not be stable, so clients should not rely on the order that multiple listeners receive events in.

##### Parameters

listener | the listener where the results of the asynchronous `connect()` call are delivered.

#### public void registerConnectionFailedListener (GooglePlayServicesClient.OnConnectionFailedListener listener)

This method is deprecated.
See `registerConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener)`.

Registers a listener to receive connection failed events from this `GooglePlayServicesClient`. Unlike `registerConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks)`, if the service is not already connected, the listener's `onConnectionFailed(ConnectionResult)` method will not be called immediately. Applications should balance calls to this method with calls to `unregisterConnectionFailedListener(OnConnectionFailedListener)` to avoid leaking resources.

If the specified listener is already registered to receive connection failed events, this method will not add a duplicate entry for the same listener.

Note that the order of messages received here may not be stable, so clients should not rely on the order that multiple listeners receive events in.

##### Parameters

listener | the listener where the results of the asynchronous `connect()` call are delivered.

#### public void resolveState (OnStateLoadedListener listener, int stateKey, String resolvedVersion, byte[] resolvedData)

This method is deprecated.
See `resolve(GoogleApiClient, int, String, byte[])`.

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.

The result is delivered to the given listener on the main thread. If `disconnect()` is called before the result is ready it will not be delivered.

##### Parameters

listener | The listener that is called when the operation is complete. This listener is required to be non-null. The listener is called on the main thread.
stateKey | The key to resolve data for. Must be a non-negative integer less than `getMaxNumKeys()`.
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()` bytes.

#### public void signOut (OnSignOutCompleteListener listener)

This method is deprecated.
See `signOut(GoogleApiClient)`.

Asynchronously signs the current user out.

The listener is called when sign-out is complete. If `disconnect()` is called before sign-out is complete, the listener will not be called.

##### Parameters

listener | The listener that is called when sign-out is complete. This listener is required to be non-null. The listener is called on the main thread.

#### public void signOut ()

This method is deprecated.
See `signOut(GoogleApiClient)`.

Asynchronously signs the current user out.

#### public void unregisterConnectionCallbacks (GooglePlayServicesClient.ConnectionCallbacks listener)

This method is deprecated.
See `unregisterConnectionCallbacks(GoogleApiClient.ConnectionCallbacks)`.

Removes a connection listener from this `GooglePlayServicesClient`. Note that removing a listener does not generate any callbacks.

If the specified listener is not currently registered to receive connection events, this method will have no effect.

##### Parameters

listener | the listener to unregister.

#### public void unregisterConnectionFailedListener (GooglePlayServicesClient.OnConnectionFailedListener listener)

This method is deprecated.
See `unregisterConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener)`.

Removes a connection failed listener from the `GooglePlayServicesClient`. Note that removing a listener does not generate any callbacks.

If the specified listener is not currently registered to receive connection failed events, this method will have no effect.

##### Parameters

listener | the listener to unregister.

#### public void updateState (int stateKey, byte[] data)

This method is deprecated.
See `update(GoogleApiClient, int, byte[])`.

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 `loadState(OnStateLoadedListener, 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 `updateStateImmediate(OnStateLoadedListener, int, byte[])` if you need the results delivered to your application.

##### Parameters

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

#### public void updateStateImmediate (OnStateLoadedListener listener, int stateKey, byte[] data)

This method is deprecated.
See `updateImmediate(GoogleApiClient, int, byte[])`.

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 delivered on the provided listener's `onStateLoaded(int, int, byte[])` method.

The result is delivered to the given listener on the main thread. If `disconnect()` is called before the result is ready it will not be delivered.

##### Parameters

listener | The listener that is called when the write operation is complete. This listener is required to be non-null. The listener is called on the main thread.
stateKey | The key to update data for. Must be a non-negative integer less than `getMaxNumKeys()`.
data | The data to store. May be a maximum of `getMaxStateSize()` bytes.