How is JobIntentService related to JobService?

In the case Service, the IntentServicemain differences Serviceare made in the main thread, but IntentServicenot, and the last one ends when the work is done, when we have to call either stopService()or stopSelf()to stop Service.

Both of them can simply be transferred to startService().

How about JobServiceu JobIntentService?

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.classrefer both to JobServiceand to JobIntentService?

Will the behavior be the same as with Serviceand IntentService(except the JobSchedulertask may not start right away)?

+14
source share
3 answers

JobIntentService IntentService, , " " Android O. O +, - , .

schedule() , JobIntentService. JobIntentService enqueue() , enqueue() schedule() .

+9

JobService JobScheduler. ExampleJobService.class JobService.

, JobIntentService :

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

JobIntentService , Android Oreo.

, Oreo, JobIntentService Context.startService.   Android O , JobScheduler.enqueue.

+8

Actually, JobIntentService would be better if it was renamed to JobedIntendService, with JobService at first glance it is not visible.

0
source

All Articles