如何取消JobIntentService [英] How to cancel a JobIntentService

查看:467
本文介绍了如何取消JobIntentService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何取消 JobIntentService ?除了JobSheduler API和Context#stopService(...)方法之外,我在文档中没有其他方法可以做到这一点,我不确定这是否是正确的方法.

How can I cancel a JobIntentService? I see no methods to do so in the docs, apart maybe from the JobSheduler API and the Context#stopService(...) method, which I'm unsure if it's the right way.

推荐答案

JobIntentService仅将IntentService带到对后台服务更为严格的Android 8+.它在具有旧版Android的设备上像旧版IntentService一样运行.

JobIntentService is only bringing IntentService to Android 8+ that is more strict about background services. It runs like old IntentServices on devices with older versions of Android.

IntentService从未被设计为要取消,因此缺少用于取消JobIntentService的任何API.

IntentService has never been designed to be cancelled, hence the lack of any API to cancel a JobIntentService.

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

Therefore, JobIntenService should only be used for work that don't need to be cancelled. Note that JobIntentService can still be used for work that can fail, and consequently, be aborted.

可以取消的工作应在以下任一情况下执行:

Work that can be cancelled should be executed in either:

  • 用于短期工作的Activity(或其ViewModel)
  • JobService(如果minSdk为21,则使用Firebase Job Dispatcher或Job Scheduler)
  • 自定义前台服务
  • An Activity (or its ViewModel) for short duration work
  • A JobService (using Firebase Job Dispatcher or Job Scheduler if minSdk is 21)
  • A custom foreground service

这篇关于如何取消JobIntentService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆