For the More Curious: JobScheduler and JobServices

In this chapter, you saw how to use AlarmManager, an IntentService, and PendingIntents to put together a periodically executing background task. In doing that, you had to do a few things manually:

  • schedule a periodic task

  • check whether that periodic task was currently running

  • check whether the network was currently up

You had to stitch a few different APIs together by hand to create one functioning background worker that you could start and stop. It worked, but it was a lot of work.

In Android Lollipop (API 21), a new API was introduced called JobScheduler that can implement these kinds of tasks on its own. It is also capable of more: For example, it can avoid starting ...

Get Android Programming: The Big Nerd Ranch Guide, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.