How is JobIntentService related to JobService?

前端 未结 3 2008
我寻月下人不归
我寻月下人不归 2021-02-12 11:36

In case of Service and IntentService the main differences are Service runs on the main thread while IntentService is not, and

相关标签:
3条回答
  • 2021-02-12 12:13

    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.

    0 讨论(0)
  • 2021-02-12 12:14

    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.

    0 讨论(0)
  • 2021-02-12 12:23

    Actually, JobIntentService would be better if rename to JobedIntendService, one get obscured with JobService at first glance.

    0 讨论(0)
提交回复
热议问题