JobScheduler: setperiodic + setRequiredNetworkType

Viewed 314

when I use setPeriodic and setRequiredNetworkType what if at the end of the period there is no RequiredNetworkType ? the task will run in any case or it's will be delayed? I mean I would like the task to be run every 30 min if their is a WIFI connection, else after one hour use any available connection.

how to do this ?

1 Answers

According to the docs for JobInfo.Builder.setRequiredNetworkType, if the required network type is not available, the job will never run. I don't think there's any callback to tell you it didn't run.

So for your case, I'd suggest having two jobs, one restricted to WiFi and one for any network type. If the WiFi job runs, it records its status, perhaps by storing the time it ran in a preference, and when the any-network job runs, it checks the preference for the last time the WiFi job ran, and only proceeds if the WiFi job hasn't run in the past hour.

Related