Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In case of Service and IntentService the main differences are Service runs on the main thread while IntentService is not, and the latter finishes itself when the work is done while we have to call either stopService() or stopSelf() to stop a Service .

Both of these can be simply passed to startService() .

What about JobService and JobIntentService ?

Let's take the following code snippet:

JobInfo job = new JobInfo.Builder(id, new ComponentName(context, ExampleJobService.class))
    .build();
JobScheduler scheduler = (JobScheduler) context
    .getSystemService(Context.JOB_SCHEDULER_SERVICE);
scheduler.schedule(job);

Can ExampleJobService.class refer to both a JobService and a JobIntentService?

Will the behaviour be the same as with Service and IntentService (apart from the JobScheduler may not start the jobs immediately)?

Actually, JobIntentService would be better if rename to JobedIntendService, one get obscured with JobService at first glance. – user1611552 Oct 15, 2019 at 11:06

JobIntentService is essentially a replacement for IntentService, offering similar semantics in a way that "plays nice" with Android O's new background execution restrictions. It is implemented as a scheduled job on O+, but that's abstracted away -- your app doesn't need to care that it's a job.

Never schedule() a job directly that you expect to use via the JobIntentService support class. JobIntentService uses the enqueue() system in the job scheduler, and you cannot mix and match enqueue() and schedule() for the same job.

IntentService was deprecated, suggesting you use JobIntentService . Unfortunately, JobIntentService is deprecated too. What should I use? – Ben Butterworth Sep 3, 2021 at 15:18

JobService is used to schedule background work with JobScheduler. The above code snippet for ExampleJobService.class can be used to start a JobService.

Where as, a JobIntentService can be started using below code:

// JobIntentService for background task
Intent i = new Intent(context, ExampleJobIntentService.class);
ExampleJobIntentService.enqueueWork(context,i);

The JobIntentService is capable to work for both before and after Android Oreo devices.

When running on older than Oreo versions of the platform, JobIntentService will use Context.startService. When running on Android O or later, the work will be dispatched as a job via JobScheduler.enqueue.

I know we can pass in time intervals for JoScheduler when running a JobService but how do I do that same thing using JobIntentService? – George Udosen Nov 19, 2018 at 9:17

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.