7. Periodic Tasks

The great enemy of communication, we find, is the illusion of it.

William H. Whyte

One of the most important varieties of asynchronous task is a task that must repeat on a schedule. Scheduled tasks usually synchronize the state of the application that contains them with some external state. Of course, whenever possible, it is better if the external state pushes change notification to the application: push notifications don’t have granularity lag and scale better than polling.

Sometime, however, polling and explicit scheduling are necessary. An application that depends on a resource that doesn’t send push notifications is going to have to poll that resource. Alternatively, sometimes conditions local to the device drive explicit ...

Get Android™ Concurrency 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.