Skip to content Skip to sidebar Skip to footer

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 t

Solution 1:

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

Post a Comment for "How To Cancel A Jobintentservice"