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.


Field Summary
static java.lang.String TAG
           
 
Constructor Summary
protected GCMBaseIntentService(java.lang.String senderId)
          Subclasses must create a public no-arg constructor and pass the sender id to be used for registration.
 
Method Summary
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(java.lang.String senderId)
Subclasses must create a public no-arg constructor and pass the sender id to be used for registration.

Method Detail

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)