In case of Service
and IntentService
the main differences are Service
runs on the main thread while IntentService
is not, and
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.