JobIntentService onhandleWork()。我已经尝试使用以下解决方案进行修复,但仍然无法正常工作。
Custom JobIntentService onHandleWork not called
这是我的代码:
清单:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<service
android:name=".service.HeropageService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
服务代码:
class HeropageService : JobIntentService() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return super.onStartCommand(intent, flags, startId)
}
override fun onHandleWork(intent: Intent) {
//Not Called
}
companion object {
val jo = 23
fun enqueueWork(context: Context, work: Intent) {
enqueueWork(context, HeropageService::class.java, jo, work)
}
}
}
这是我致电服务的方式:
viewModel!!.newslistResponse.observe(this@HeroPageActivity, Observer {
if (it != null) {
val intentUpload = Intent(this@HeroPageActivity, HeropageService::class.java)
HeropageService.enqueueWork(this@HeroPageActivity, intentUpload)
}
})
我真的不知道我缺少什么,请帮帮我。 预先感谢