Android-job: Is there possible to run a periodic job with offset?

Created on 4 Jul 2017  路  7Comments  路  Source: evernote/android-job

Let's say I have a periodic job and will run every 15mins. But I want the first time run is 15 mins later not immediately. I have read the doc and source code and cannot find a public api to do it..
Any help?

question

All 7 comments

Periodic jobs should work this way. Usually it waits one period until the job runs for the first time.

@vRallev I schedule job when application oncreate. After test, when my app start, the onRunJob callback will be called immediately...
here is my job code.

    private void scheduleNetworkJob() {
        int jobId = new JobRequest.Builder(NetworkChangeJob.TAG)
                .setPeriodic(JobRequest.MIN_INTERVAL)
                .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
                .setPersisted(true)
                .setUpdateCurrent(true)
                .build()
                .schedule();
    }

Sorry, but I don't have a better solution than to manually skip the first period. You can either use the shared preferences or you can also check when the job was scheduled.

You can create two jobs where the first is executed once after an offset and it will execute the 2nd which will be periodic.

@vRallev
It would be very good to make possible to use .setExact(...) and .setPeriodic(...) both in one job...

You can do this on your own, but I wouldn't recommend it. That's against the whole purpose of this library to make background jobs as battery friendly as possible.

Closing because of inactivity.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adek picture adek  路  6Comments

pyricau picture pyricau  路  7Comments

jsu4650 picture jsu4650  路  5Comments

vibin picture vibin  路  3Comments

karntrehan picture karntrehan  路  5Comments