如何取消JobIntentService

时间:2017-08-28 15:10:25

标签: android android-support-library

如何取消JobIntentService?我在文档中看不到任何方法,除了JobSheduler API和Context#stopService(...)方法,我不确定它是否正确。

2 个答案:

答案 0 :(得分:1)

在Android 8.0之前,JobIntentService被实现为IntentService。在IntentService方法完成上一个请求之前,onHandleIntent不会通过某些意图操作停止或接受任何其他请求。 在任务完成之前不会调用stopService()。它会自动调用。这是IntentService的一个特征,但是类似的问题在这里已经回答了IntentServices,希望它有所帮助。

answered question

还可以查看android developers

答案 1 :(得分:1)

JobIntentService只会将IntentService带到Android 8+,后者对后台服务更加严格。它与旧版本的Android设备上的旧版IntentService一样运行。

IntentService从未设计为取消,因此缺少取消JobIntentService的API。

因此, JobIntenService只应用于不需要取消的作品。请注意,JobIntentService仍可用于的工作失败,因此被中止。

可以取消的工作应该是:

  • Activity(或其ViewModel)短期工作
  • JobService(如果minSdk为21,则使用Firebase作业调度程序或作业计划程序)
  • 自定义前台服务