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?
android android-service google-cloud-messaging gcmtaskservice
Mattias Petter Johansson
source share