I'm trying to get my app working on Android 9. The following code works fine up to Android 8, but for some reason, the JobService does not get rescheduled on android 9. It gets scheduled the first time but does not get rescheduled according to the set periodic.
class RetrieveJobService : JobService() {
override fun onStartJob(params: JobParameters): Boolean {
doBackgroundWork(params)
return true
}
private fun doBackgroundWork(params: JobParameters) {
Thread {
try {
doRetrieveBackgroundStuff(this)
jobFinished(params, false)
} catch (e: Exception) {
jobFinished(params, false)
}
}.start()
}
override fun onStopJob(params: JobParameters): Boolean {
return false
}
}
And here my JobInfo.Builder
val builder = JobInfo.Builder(jobID, componentName)
.setPersisted(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
builder.setPeriodic(millis, 15 * 60 * 1000) //15 min
} else {
builder.setPeriodic(millis)
}
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
val scheduler = context.getSystemService(JOB_SCHEDULER_SERVICE) as
JobScheduler
val resultCode = scheduler.schedule(builder.build())
Any ideas? EDIT: Just to be clear, this code worked fine on Android 8 and below and does also work on the Android Studio emulator running Android 9. As far as I can test, it does not work on any physic device running Android 9.