googlearchive / firebase-jobdispatcher-android

DEPRECATED please see the README.md below for details.
Apache License 2.0
1.79k stars 208 forks source link

Kotlin inferred type mismatch #231

Closed KonradSzewczuk closed 6 years ago

KonradSzewczuk commented 6 years ago

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<out JobService!>! was expected

How to setup it in Kotlin correctly?

muratoreT commented 6 years ago

At first view, your code looks good. Can you specify the exact line, where this error is happening? Do you get any errors in your MyJobService class?

KonradSzewczuk commented 6 years ago

It gives me an error by underline only the ".java" keyword in line:

.setService(MyJobService::class.java)

I don't have any errors in MyJobService class

KonradSzewczuk commented 6 years ago

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