public class

OfflineAppData

extends Object
implements Observer
java.lang.Object
   ↳ com.kinvey.android.offline.OfflineAppData<T>

Class Overview

This class allows for managing a collection while the client is offline, and syncing with Kinvey when a connection is restored.

The OfflineStore class maintains the latest state of all Entities, as well as a queue of all REST requests made while offline.

When there are requests in the queue, an Android Service will be started to pull these requests and send them to Kinvey.

This class provides offline storage for data, queueing up REST requests, executing those requests, and updating the offline store with results.

NOTE while the offline data store is persistent, it will be empty when it is first created and needs to be seeded-- take this into consideration when designing an app to function offline. This initial seeding can happen by calling save on offlineAppData

Summary

Public Constructors
OfflineAppData(String collectionName, Class myClass, AbstractClient client, Context context)
Constructor to instantiate the Offline AppData class.
Public Methods
void delete(String entityID, KinveyDeleteCallback callback)
Delete an entity from an offline collection.
void getEntity(String entityID, KinveyClientCallback<T> callback)
Get an entity or entities from an offline collection.
int getEntityCount()
Get how many entities are locally persisted to disk
List<OfflineRequestInfo> getFailedCalls()
Get a list of requests executed by the background executor which failed.
int getQueueSize()
Get how many requests are queued up for execution when a connection is restored.
List<OfflineRequestInfo> getSuccessfulCalls()
Get a list of requests executed by the background executor which were successful.
OfflineSettings offlineSettings()
Gets the instance of the OfflineSettings singleotn class
void save(T entity, KinveyClientCallback<T> callback)
Save (create or update) an entity to an offline collection.
void setCallback(KinveySyncCallback callback)
Set a callback to retrieve updates on live execution of requests in background
void update(Observable observable, Object o)
Called by the com.kinvey.android.offline.OfflineStore when an update occurs.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.Observer

Public Constructors

public OfflineAppData (String collectionName, Class myClass, AbstractClient client, Context context)

Constructor to instantiate the Offline AppData class.

Parameters
collectionName Name of the appData collection
myClass Class Type to marshall data between.

Public Methods

public void delete (String entityID, KinveyDeleteCallback callback)

Delete an entity from an offline collection.

Parameters
entityID entityID to delete
Returns
  • Delete object
Throws
IOException

public void getEntity (String entityID, KinveyClientCallback<T> callback)

Get an entity or entities from an offline collection. Pass null to entityID to return all entities in a collection.

Parameters
entityID entityID to get
Returns
  • Get object
Throws
IOException

public int getEntityCount ()

Get how many entities are locally persisted to disk

Returns
  • the size of the internal store maintaining offline entities.

public List<OfflineRequestInfo> getFailedCalls ()

Get a list of requests executed by the background executor which failed.

Returns
  • list of failed offline requests

public int getQueueSize ()

Get how many requests are queued up for execution when a connection is restored.

Returns
  • size of internal queue representing count of pending calls.

public List<OfflineRequestInfo> getSuccessfulCalls ()

Get a list of requests executed by the background executor which were successful.

Returns
  • list of successful offline requests

public OfflineSettings offlineSettings ()

Gets the instance of the OfflineSettings singleotn class

Returns
  • OfflineSettings instance

public void save (T entity, KinveyClientCallback<T> callback)

Save (create or update) an entity to an offline collection.

Parameters
entity Entity to Save
Returns
  • Save object
Throws
IOException

public void setCallback (KinveySyncCallback callback)

Set a callback to retrieve updates on live execution of requests in background

Parameters
callback instance of a callback to receive updates.

public void update (Observable observable, Object o)

Called by the com.kinvey.android.offline.OfflineStore when an update occurs.

Parameters
observable - the Offline Store
o - the Request Info of the update.