Chapter  17

Exploring Handlers

We showed in Chapter 16 that each package runs in its own process. In this chapter, we will explain the organization of threads within this process. This will lead us to why we need handlers.

Most code in an Android application runs in the context of a component such as an activity or a service. We will show how these components of an application interact with threads. Most of the time there is only one thread running in an Android process, called the main thread. We will talk about the implications of sharing this main thread among various components. Primarily, this can lead to Application Not Responding (ANR) messages (the “A” stands for “application” and not “Annoying”). We will show you how you can use handlers, ...

Get Pro Android 4 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.