Android APIs
public abstract class

BaseEventService

extends IntentService
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.app.IntentService
           ↳ com.google.android.gms.cloudsave.BaseEventService

Class Overview

Base implementation of Service for listening to CloudSave events. The implementation of this service needs to be registered in application’s manifest as follows

 
   <manifest ...>
       <application ...>
           <service android:name=<YOUR_SERVICE>
                         android:permission="com.google.android.gms.cloudsave.EVENT_BROADCAST" >
               <intent-filter>
                   <action android:name="com.google.android.gms.cloudsave.EVENT" />
               </intent-filter>
           ...
       </application>
   </manifest>
 
 
Permission "com.google.android.gms.cloudsave.EVENT_BROADCAST" makes sure that the service will only listen to events sent by CloudSave. This protects the app from other malicious apps that might want to inject events.

Summary

[Expand]
Inherited Constants
From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2
Protected Constructors
BaseEventService(String name)
Protected Methods
Status applyRemoteChanges(String context)
Signals the CloudSave service to apply the current set of remote changes.
abstract Entity onConflict(Entity localEntity, Entity baseEntity, Entity remoteEntity)
This method is called when there is a conflict between the local version of a given Entity and remote server version.
void onError(int errorCode, String desc)
Notifies about CloudSave errors that happen when performing async background tasks like background syncing.
void onHandleIntent(Intent intent)
void onRemoteChanged(List<Entity.Key> entityKeys, String context)
This method is called when a change in App's data is found on the remote server.
[Expand]
Inherited Methods
From class android.app.IntentService
From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2

Protected Constructors

protected BaseEventService (String name)

Protected Methods

protected Status applyRemoteChanges (String context)

Signals the CloudSave service to apply the current set of remote changes. The remote changes do not get merged into local db till this method is called. This method is called by the default implementation of onRemoteChanged() already and hence does not need to be called by the App explicitly unless the onRemoteChanged() is being overridden. See onRemoteChanged(List, String) for more details.

Parameters
context String context provided by onRemoteChanged(List, String)
Returns
  • Status result specifying if the call was successful or not

protected abstract Entity onConflict (Entity localEntity, Entity baseEntity, Entity remoteEntity)

This method is called when there is a conflict between the local version of a given Entity and remote server version. It allows the application to do a three way merge for the given conflict.

Parameters
localEntity represents the current view of the Entity in local database.
baseEntity represents the last common view of the Entity between local db and server. This is the nearest common ancestor of localEntity and remoteEntity.
remoteEntity represents the current view of the Entity on remote server.
Returns
  • a Entity representing a consistent merger of localEntity and remoteEntity.

protected void onError (int errorCode, String desc)

Notifies about CloudSave errors that happen when performing async background tasks like background syncing.

Parameters
errorCode integer error code based on the type of error
desc a human readable description of the error

protected void onHandleIntent (Intent intent)

protected void onRemoteChanged (List<Entity.Key> entityKeys, String context)

This method is called when a change in App's data is found on the remote server. The default implementation invokes applyRemoteChanges(String) to apply these changes. Overriding this method allows an app to 1) Intercept the event and update UI or clean up data that the app may be storing locally. In this case the overridden method must call super() to make sure that the remote changes are applied to the local database. 2) Delay application of the remote changes. In this case don't call super() from the overridden method. In this case, the burden of making sure that applyRemoteChanges(String) is called rests on the App's shoulder. Extreme care needs to be taken in this case as bad handling of this can end up stopping the App from syncing with remote server. Note: The remote changes do not get merged into local db till applyRemoteChanges(String) is called. If the remote changes are not applied then all remote syncs henceforth will invoke this event and a new remote sync will not happen till the previous changes are applied.

Parameters
entityKeys Entity.Key for the Entities that have changed.
context for this set of changes. This is used by applyRemoteChanges(String)