Chapter 15. Summary: Selecting an Asynchronous Technique
As we’ve seen, the Android platform provides us with many asynchronous techniques to help us run tasks both concurrently and off the UI thread. Without these techniques, it wouldn’t be possible to implement a fast and responsive application, so they become part of the core functionality. The range of techniques are there to assist us and make life easier, but we always have to make choices about which techniques to use. Sometimes the choice is easy—e.g., CursorLoader
when reading data from a provider—but often we face situations where several mechanisms could solve the problem. In those situations, it’s a natural habit to fall back on a mechanism we know and have used before. This may, however, be a suboptimal choice, and we should aim for something better, based on a set of conditions about each technique:
- It uses the fewest system resources—i.e., CPU cycle and memory—as necessary.
- It provides the application with maximum performance and responsiveness.
- It allows low implementation effort.
- It provides a good code design, making it easy to understand and maintain.
This chapter summarizes the asynchronous techniques and how to choose between them. First, let’s take a look at the relationships among the mechanisms, shown in Figure 15-1. The Thread
is the fundamental entity of all mechanisms. Features supporting the asynchronous execution are added further up in the hierarchy, each invoking the following features.
Get Efficient Android Threading 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.