android - GCM Network Manager - Periodic Task not firing -


i'm attempting use gcmnetworkmanager schedule recurring task in app, runs down api level 17. i've set explained on gcm network manager page (https://developers.google.com/cloud-messaging/network-manager):

in androidmanifest.xml, have:

<service     android:name=".services.myservice"     android:exported="true"     android:permission="com.google.android.gms.permission.bind_network_task_service">     <intent-filter>         <action android:name="com.google.android.gms.gcm.action_task_ready"/>     </intent-filter> </service> 

in application, have:

long periodsecs = 30l; // task should executed every 30 seconds long flexsecs = 15l; // task can run -15 seconds scheduled time  string tag = "myscan|1";  periodictask periodic = new periodictask.builder()         .setservice(myservice.class)         .setperiod(periodsecs)         .setflex(flexsecs)         .settag(tag)         .setpersisted(false)         .setrequirednetwork(com.google.android.gms.gcm.task.network_state_any)         .setrequirescharging(false)         .setupdatecurrent(true)         .build();  gcmnetworkmanager.getinstance(this).schedule(periodic); 

and have myservice, looks like:

public class myservice extends gcmtaskservice {     @override     public int onruntask(taskparams taskparams) {         log.info("onruntask: " + taskparams.gettag());          return gcmnetworkmanager.result_success;     }      @override     public int onstartcommand (intent intent, int flags, int startid) {         log.info("onstartcommand");          return gcmtaskservice.start_sticky_compatibility;     } } 

when start app, onstartcommand logged expected, onruntask never gets called. missing something? i'm expecting that, once started (as evidenced start command firing), should run every 15-30 seconds - correct assumption? why isn't firing @ all?

thanks!

the problem overriding onstartcommand! how google play services executes task on gcmtaskservice. if want work simply

return super.onstartcommand(intent, flags, startid); 

perhaps it's worth mentioning reason onruntask provided don't have worry service's lifecycle - can rely on internals of gcmtaskservice stopservice when required.

that said, if startservice() on gcmtaskservice custom intents mess , end service isn't stopped when should be.

if need call in gcmtaskservice (not recommended) should bind - interface untouched gcmtaskservice internals.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -