com.google.android.gcm
Class GCMBaseIntentService

java.lang.Object
  extended by IntentService
      extended by com.google.android.gcm.GCMBaseIntentService

public abstract class GCMBaseIntentService
extends IntentService

Skeleton for application-specific IntentServices responsible for handling communication from Google Cloud Messaging service.

The abstract methods in this class are called from its worker thread, and hence should run in a limited amount of time. If they execute long operations, they should spawn new threads, otherwise the worker thread will be blocked.

Subclasses must provide a public no-arg constructor.


Field Summary
static java.lang.String TAG
           
 
Constructor Summary
protected GCMBaseIntentService()
          Constructor that does not set a sender id, useful when the sender id is context-specific.
protected GCMBaseIntentService(java.lang.String... senderIds)
          Constructor used when the sender id(s) is fixed.
 
Method Summary
protected  java.lang.String[] getSenderIds(Context context)
          Gets the sender ids.
protected  void onDeletedMessages(Context context, int total)
          Called when the GCM server tells pending messages have been deleted because the device was idle.
protected abstract  void onError(Context context, java.lang.String errorId)
          Called on registration or unregistration error.
 void onHandleIntent(Intent intent)
           
protected abstract  void onMessage(Context context, Intent intent)
          Called when a cloud message has been received.
protected  boolean onRecoverableError(Context context, java.lang.String errorId)
          Called on a registration error that could be retried.
protected abstract  void onRegistered(Context context, java.lang.String registrationId)
          Called after a device has been registered.
protected abstract  void onUnregistered(Context context, java.lang.String registrationId)
          Called after a device has been unregistered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG

public static final java.lang.String TAG
See Also:
Constant Field Values
Constructor Detail

GCMBaseIntentService

protected GCMBaseIntentService()
Constructor that does not set a sender id, useful when the sender id is context-specific.

When using this constructor, the subclass must override getSenderIds(Context), otherwise methods such as onHandleIntent(Intent) will throw an IllegalStateException on runtime.


GCMBaseIntentService

protected GCMBaseIntentService(java.lang.String... senderIds)
Constructor used when the sender id(s) is fixed.

Method Detail

getSenderIds

protected java.lang.String[] getSenderIds(Context context)
Gets the sender ids.

By default, it returns the sender ids passed in the constructor, but it could be overridden to provide a dynamic sender id.

Throws:
java.lang.IllegalStateException - if sender id was not set on constructor.

onMessage

protected abstract void onMessage(Context context,
                                  Intent intent)
Called when a cloud message has been received.

Parameters:
context - application's context.
intent - intent containing the message payload as extras.

onDeletedMessages

protected void onDeletedMessages(Context context,
                                 int total)
Called when the GCM server tells pending messages have been deleted because the device was idle.

Parameters:
context - application's context.
total - total number of collapsed messages

onRecoverableError

protected boolean onRecoverableError(Context context,
                                     java.lang.String errorId)
Called on a registration error that could be retried.

By default, it does nothing and returns true, but could be overridden to change that behavior and/or display the error.

Parameters:
context - application's context.
errorId - error id returned by the GCM service.
Returns:
if true, failed operation will be retried (using exponential backoff).

onError

protected abstract void onError(Context context,
                                java.lang.String errorId)
Called on registration or unregistration error.

Parameters:
context - application's context.
errorId - error id returned by the GCM service.

onRegistered

protected abstract void onRegistered(Context context,
                                     java.lang.String registrationId)
Called after a device has been registered.

Parameters:
context - application's context.
registrationId - the registration id returned by the GCM service.

onUnregistered

protected abstract void onUnregistered(Context context,
                                       java.lang.String registrationId)
Called after a device has been unregistered.

Parameters:
registrationId - the registration id that was previously registered.
context - application's context.

onHandleIntent

public final void onHandleIntent(Intent intent)