student93
student93

Reputation: 307

setRequiredNetworkType doesn't work on periodic tasks?

The following bit of code, from my understanding, is supposed to set a periodic job that only runs if there is a network connectivity. Meaning that despite being periodic, it won't run unless the required condition is met.

But that doesn't work. It always runs after the period no matter if there is a network or not. Am I doing something wrong ?

  JobScheduler mJobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo.Builder builder = null;
        builder = new JobInfo.Builder(1, new ComponentName(getPackageName(),
                MyJobService.class.getName()))
                .setPersisted(true)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
                .setPeriodic(10 * 1000);

Upvotes: 3

Views: 1055

Answers (1)

Sagar
Sagar

Reputation: 24907

There were some issues with setPeriodic() on Android Version < N (Although I don't have official link to issue) but using setMinimumLatency() on older versions did the trick for me.

You can check this SO for further details.

Upvotes: 1

Related Questions