0

I'm using Evernote's JobScheduler. The library provides a way to set a periodic job, however that has a minimum interval of 15 minutes between repetitions.

I want to be able to send a user's location to the server every few minutes (maximum 3, minimum 2). Is it technically OK to schedule your old job again and again after the job is done? Something like this:

protected Result onRunJob(Params params)
{
    // my actual job runs here

    schedulePeriodicJob();
    return Result.SUCCESS;
}

private void schedulePeriodicJob()
{
    jobId = new JobRequest.Builder(ScheduleJob.TAG)
            .setExact(TimeUnit.MINUTES.toMillis(2))
            .setBackoffCriteria(TimeUnit.MINUTES.toMillis(1), JobRequest.BackoffPolicy.LINEAR)
            .build()
            .schedule();
}

Or should I simply use a foreground service to achieve this?

Piyush
  • 18,895
  • 5
  • 32
  • 63
Asim
  • 6,962
  • 8
  • 38
  • 61

1 Answers1

0

Evernote job scheduler is based upon JobScheduler, GcmNetworkManager or AlarmManager depending on the context/device/playservices version. Whatever the implementation, APIs exposes the following method:

public JobRequest.Builder setPeriodic(long intervalMs, long flexMs)

I would use this one instead of "manually" rescheduling job. I also don't think your setBackoffCriteria call would not work without setting recurring job at APIs level.

Shine
  • 3,788
  • 1
  • 36
  • 59