Android APIs
public abstract class

GcmTaskService

extends Service
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ com.google.android.gms.gcm.GcmTaskService

Class Overview

Implemented by the client application to provide an endpoint for the GcmNetworkManager to call back to when a task is ready to be executed.

Clients must add this service to their manifest and implement onRunTask(String). This service must provide an IntentFilter on the action ACTION_TASK_EVENT. Here's an example:

 

The return value of onRunTask(String) will determine whether the scheduler treats this execution as a success, in which case it continues normally, as a failure, in which the task will be dropped, or whether the task is re-added to the execution queue and exponentially backed-off.

Rescheduling a task will reset the back-off counter. Once a task is running it will not be cancelled, however a newly scheduled task with the same tag will not be executed until the active task has completed. This newly scheduled task will replace the previous task, regardless of whether the previous task was meant to be rescheduled.

Bear in mind that your service may receive multiple calls from the scheduler at once (specifically if you've made multiple schedule requests that overlap), so your implementation of onRunTask(String) must be thread-safe.

The scheduler will hold a PowerManager.WakeLock for your service, however after three minutes of execution if your task has not returned it will be considered to have timed out, and the wakelock will be released. Rescheduling your task at this point will have no effect. If you suspect your task will run longer than this you should start your own service explicitly or use some other mechanism; this API is intended for relatively short time-span network operations.

Summary

Constants
String PERMISSION_BIND You must protect your service with this permission to avoid being bound to by an application other than Google Play Services.
String TAG
[Expand]
Inherited Constants
From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2
Public Constructors
GcmTaskService()
Public Methods
IBinder onBind(Intent intent)
abstract int onRunTask(String tag)
Override this function to provide the logic for your task execution.
int onStartCommand(Intent intent, int flags, int startId)
Receives the command to begin doing work, for which it spawns another thread.
[Expand]
Inherited Methods
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

Constants

public static final String PERMISSION_BIND

You must protect your service with this permission to avoid being bound to by an application other than Google Play Services.

Constant Value: "com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"

protected static final String TAG

Constant Value: "GcmTaskService"

Public Constructors

public GcmTaskService ()

Public Methods

public IBinder onBind (Intent intent)

public abstract int onRunTask (String tag)

Override this function to provide the logic for your task execution.

Parameters
tag String provided at schedule time in scheduleTask(long, long, String)

public int onStartCommand (Intent intent, int flags, int startId)

Receives the command to begin doing work, for which it spawns another thread.