5. Looper/Handler
The ants go marching one by one. Hurrah! Hurrah!
Children’s song
Although AsyncTasks are the first concurrency construct that most developers encounter when they start working with Android, they are not its central concurrency construct. The basic concurrency construct in Android is the Looper/Handler.
Introducing the Looper/Handler
The Looper/Handler framework, like several other important parts of Android’s internal architecture, was probably inspired by the BeOS operating system—in particular, its BLooper
and BHandler
classes.
The Looper framework is an extension of the safe publication idiom, introduced Chapter 2, “Java Concurrency,” and shown again in Figure 5.1. The idiom consists of a drop box and a lock on that drop ...
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.