Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin inferred type mismatch

Tags:

android

kotlin

I try to setup JobService using FirebaseJobDispatcher.

Here is my JobService:

class MyJobService : JobService() {
override fun onStartJob(job: JobParameters): Boolean {
    // Do some work here
   return false //return false if job done otherwise return true
}

override fun onStopJob(job: JobParameters): Boolean {
    return false //Should this job be retried?"
   }
}

However when i try to setup it like this:

val dispatcher = FirebaseJobDispatcher(GooglePlayDriver(this))
val myJob = dispatcher.newJobBuilder()
    .setService(MyJobService::class.java) // the JobService that will be called
    .setTag("my-unique-tag")        // uniquely identifies the job
    .build()

I am getting this compiler error in Android Studio:

Type inference failed. Expected type mismatch: inferred type is Class but Class! was expected

How to setup it in Kotlin correctly?

like image 424
K.Os Avatar asked Apr 27 '18 13:04

K.Os


1 Answers

It seems that I imported wrong JobService.

Instead of:

import android.app.job.JobParameters
import android.app.job.JobService

Should be:

import com.firebase.jobdispatcher.JobParameters
import com.firebase.jobdispatcher.JobService
like image 168
K.Os Avatar answered Oct 06 '22 00:10

K.Os