9

I am inspecting the latest samples in Android-L developer SDK. There is a sample class in android-L/ui/views/Clipping/ClippingBasic called TestJobService. It extends from JobService, which in turn extends from Service. I see that JobService is a class in android.jar, but I cannot find any information on it in the dev guides, nor in the Android sourcecode www.androidxref.com. Has anybody seen this class or know what it's purpose is?

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147

2 Answers2

10

It's a new type of service, that is invoked for tasks that are scheduled to be run depending on system conditions (e.g. idle, plugged in).

Entry point for the callback from the JobScheduler.

This is the base class that handles asynchronous requests that were previously scheduled. You are responsible for overriding onStartJob(JobParameters), which is where you will implement your job logic.

You basically create a JobInfo object that describes these conditions (with JobInfo.Builder) and set the component name of the service that must be executed.

To schedule them, you need the JobScheduler, which you can access with Context.getSystemService(Context.JOB_SCHEDULER_SERVICE).

By the way, L Preview Documentation is here, in case you didn't know about it.

UPDATE: Here is the doc about JobService: https://developer.android.com/reference/android/app/job/JobService.html

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
matiash
  • 54,791
  • 16
  • 125
  • 154
  • @matiash The link you provided has no information about JobService. – IgorGanapolsky Jul 07 '14 at 15:33
  • @IgorGanapolsky You need to download the zip file, and then check `/reference/android/app/job/JobService.html`. The documentation for L is not merged with the official online docs yet. – matiash Jul 07 '14 at 15:35
3

You can go through this article, for a thorough understanding of the topic -

https://medium.com/google-developers/scheduling-jobs-like-a-pro-with-jobscheduler-286ef8510129

Our goal with JobScheduler was to find a way for the system to shoulder part of the burden of creating performant apps. As a developer, you do your part to create an app that doesn’t freeze, but that doesn’t always translate to the battery life of the device being healthy. So, by introducing JobScheduler at the system level, we can focus on batching similar work requests together, which results in a noticeable improvement for both battery and memory.

  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – FelixSFD Aug 16 '17 at 18:35
  • 1
    The details given in the link is really elaborate and convincing. I am putting a part of it in the answer. But, it will be really helpful if one visits the link to have a clear understanding. – Satyaki Mallick Aug 16 '17 at 18:42