Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android JobIntentService is deprecated

Tags:

android

The JobIntentService class appears to be deprecated. Yet the Android documentation for services says: "You can use JobIntentService as a replacement for IntentService that is compatible with newer versions of Android."

So what are we supposed to replace JobIntentService with?

like image 433
tronman Avatar asked Aug 07 '21 20:08

tronman


People also ask

Why is JobIntentService deprecated?

This class is deprecated. This class has been deprecated in favor of the Android Jetpack WorkManagerlibrary, which makes it easy to schedule deferrable, asynchronous tasks that are expected to run even if the app exits or the device restarts.

What is difference between IntentService and JobIntentService?

Both work same but the only difference with JobIntentService is that JobIntentService gets restarted if the application gets killed while the service was executing.

Are services deprecated Android?

Moreover, it's deprecated starting with Android 11. You can use JobIntentService as a replacement for IntentService that is compatible with newer versions of Android.

What is the use of JobIntentService?

You can say JobIntentService is a modern way to run the background service from the background application. JobIntentService works in the same way as a Service however it enqueues the work into the JobScheduler on compatible Android targets( SDK 26 or more).


Video Answer


1 Answers

As @CommonsWare pointed out, I had two options for replacing my JobIntentService:

  1. Using a foreground service
  2. Using a WorkManager with a long-running worker

The Android documentation on services states:

The WorkManager API offers a flexible way of scheduling tasks, and is able to run these jobs as foreground services if needed. In many cases, using WorkManager is preferable to using foreground services directly.

Since Google seems to be pushing folks towards WorkManager, that's what I decided to use.

like image 112
tronman Avatar answered Oct 26 '22 22:10

tronman