[英]Kotlin inferred type mismatch
I try to setup JobService using FirebaseJobDispatcher. 我尝试使用FirebaseJobDispatcher设置JobService。
Here is my JobService: 这是我的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: 我在Android Studio中收到此编译器错误:
Type inference failed. 类型推断失败。 Expected type mismatch: inferred type is Class but Class! 预期类型不匹配:推断类型是Class但Class! was expected 预计
How to setup it in Kotlin correctly? 如何在Kotlin中正确设置它?
It seems that I imported wrong JobService. 好像我导入了错误的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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.