Chapter 3. Managing lifecycle and state
In this chapter
- Understanding application processes and users
- Exploring Activity lifecycle
- Handling Activity instance state
- Understanding tasks and task affinity
Each thing is of like form from everlasting and comes round again in its cycle.
Marcus Aurelius
All Android applications are created equal. This isn’t some ideological ideal; it’s a truth born out of necessity. Many Android devices—as we’ve already noted a few times but will hammer home again even at the risk of repetition—have limited memory, CPU power, and other resources. Because of these factors, when the platform was created, the design had to include a way to give the most important processes the resources they needed, and at the same time subdue or kill other processes that might get in the way.
Android handles this by managing application processes within a hierarchy where the current and most recently used components are at the top. When resources get scarce, the platform will kill the least-relevant processes. In addition, Android components use a series of lifecycle methods that act as callbacks—the platform hooks into these methods to create and destroy components (and move them through other stages as well).