Android-job: daily job not working

Created on 30 May 2018  路  6Comments  路  Source: evernote/android-job

I use daily job scheduler just like the sample in faq page

'class DailyJobSchedule : DailyJob() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onRunDailyJob(params: Params): DailyJobResult {
    callDb(Room.databaseBuilder(context, LogsDataBase::class.java, DATA_BASE_NAME).build()) {
        it.observerElementDao().insertOrUpdate(Log(Date().time,"onRunDailyJob=${sdf.format(Date())}"))
    }

    return DailyJob.DailyJobResult.SUCCESS
}

companion object {
    val TAG = "MyDailyJob"

    fun schedule() {
        DailyJob.schedule(
                JobRequest.Builder(TAG)
                        .setRequiresDeviceIdle(true)
                        .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
                , TimeUnit.HOURS.toMillis(1), TimeUnit.HOURS.toMillis(6)
        )

    }
   }
   }

`
but it does not run at all just when in next day I pick up the phone job called.
the phone is asus_z017d android8 API 26
I know about doze mode I don't think that's the problem because in doze mode jobs starts with a delay but they start right?

question

Most helpful comment

@vRallev I have the exact same issue. I have scheduled multiple daily jobs using different job tags. These jobs will run and make a network call to fetch some data. Now there is a weird behavior in this case.

1) These jobs run perfectly when the app is in foreground but fails to make a network call when in background or killed state.

2) Now these failed daily jobs are accumulated and are fired when I launch my app.

Just to give a brief that I too have enforced network requirements.

**Also tried removing network requirements but no success at all. Works fine when the app is in foreground but fails if in background or killed state.

All 6 comments

Can you provide a sample app? It's not unlikely that your job is delayed because of Doze, especially since you also have other requirements like a network connection. In Doze mode you usually don't have a network connection, that's why your job is delayed until you turn the screen on.

this is my sample https://github.com/mohamadk/EvernoteJobSchedulerTest
about delay in google document says https://developer.android.com/training/monitoring-device-state/doze-standby

Figure 1. Doze provides a recurring maintenance window for apps to use the network and handle pending activities.

so it must run not at exact 1 am but it must run. correct?

any progress?

I looked into it and the problem is that you set the requirements. The library relies on the JobScheduler and it triggers the job. There's nothing I could do.

Closing because of inactivity.

@vRallev I have the exact same issue. I have scheduled multiple daily jobs using different job tags. These jobs will run and make a network call to fetch some data. Now there is a weird behavior in this case.

1) These jobs run perfectly when the app is in foreground but fails to make a network call when in background or killed state.

2) Now these failed daily jobs are accumulated and are fired when I launch my app.

Just to give a brief that I too have enforced network requirements.

**Also tried removing network requirements but no success at all. Works fine when the app is in foreground but fails if in background or killed state.

Was this page helpful?
0 / 5 - 0 ratings