如何取消JobIntentService?我在文档中看不到任何方法,除了JobSheduler
API和Context#stopService(...)
方法,我不确定它是否正确。
答案 0 :(得分:1)
在Android 8.0之前,JobIntentService
被实现为IntentService
。在IntentService
方法完成上一个请求之前,onHandleIntent
不会通过某些意图操作停止或接受任何其他请求。
在任务完成之前不会调用stopService
()。它会自动调用。这是IntentService
的一个特征,但是类似的问题在这里已经回答了IntentServices
,希望它有所帮助。
还可以查看android developers
答案 1 :(得分:1)
JobIntentService
只会将IntentService
带到Android 8+,后者对后台服务更加严格。它与旧版本的Android设备上的旧版IntentService
一样运行。
IntentService
从未设计为取消,因此缺少取消JobIntentService
的API。
因此, JobIntenService
只应用于不需要取消的作品。请注意,JobIntentService
仍可用于的工作失败,因此被中止。
可以取消的工作应该是:
Activity
(或其ViewModel
)短期工作