Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

android - How to cancel a JobIntentService

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 has never been designed to be cancelled, hence the lack of any API to cancel a 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:

  • 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...