GCM Network Manager lost his job

I am trying to use GCM Network Manager to send logs to the backend service. We have an alarm clock that starts every hour, which creates OneoffTask, which, when executed, will call a backend service with a log message.

This works, BUT a very large number of Tasks are lost (more than half). At first I thought it had something to do with our backend or network, but after adding a ton of file registration, it turns out that onRunTask in the service never starts for these tasks (but they are definitely planned. I lost this? I misunderstand the API, or are OneoffTasks just unreliable?

So planned OneoffTask:

GcmNetworkManager.getInstance(context).schedule(new OneoffTask.Builder() .setService(AvroLogService.class) .setExtras(bundle) // A mandatory tag which identifies the task // We add a unique hash to the tag to make sure that // tasks are logged and not thrown away as dupes. // See: http://stackoverflow.com/q/34528960/304262 .setTag(java.util.UUID.randomUUID().toString()) // Persist to disk, even across boots: .setPersisted(true) // Sets a time frame for the execution of this task in seconds. // This specifically means that the task can either be // executed right now, or at latest at a certain point: .setExecutionWindow(0, TWO_WEEKS_IN_SECONDS) .build()); 

Again, this does not work, but only part of the messages. For messages that are subsequently lost, the above code (I added file registration to check this), but the corresponding onRunTask for the lost was never called.

I checked that:

  • The manifest is updated in accordance with the Network Manager Implementation Guide ( https://developers.google.com/cloud-messaging/network-manager )
  • AvroLogService (my service) extends GcmTaskService
  • It overrides onRunTask
  • The application has permission RECEIVE_BOOT_COMPLETED.
  • AvroLogService does NOT override onStartCommand.

I'm lost. Can anyone tell about this?

+7
android android-service google-cloud-messaging gcmtaskservice
source share
2 answers

As I understand it, your permanent TWO_WEEKS_IN_SECONDS really means 2 WEEKS. In this case, your task can be performed at any time up to 2 WEEKS. Therefore, this task should not be performed every hour. Try setting a run window within one hour or less ( .setExecutionWindow(0, HALF_AN_HOUR_IN_SECONDS) )

See google api docs

0
source share

As the answer above, the runtime range can be large. Also I think that you want to execute the event periodically, try using PeriodicTask.Builder instead of OneoffTask.Builder

0
source share

All Articles