Chapter 5. The Activity Lifecycle: Being an Activity
Activities form the foundation of every Android app.
So far youâve seen how to create an activity, and use it to interact with the user. But if you donât know about the activity lifecycle, some of its behavior might take you by surprise. In this chapter, youâll learn what happens when an activity is created and destroyed, and how this can lead to unexpected consequences. Youâll find out how to control its behavior when itâs made visible, or hidden. Youâll even discover ways of saving and restoring your activityâs state, just when you need it. Read on to find out moreâ¦
How do activities really work?
So far youâve seen how to create an interactive app by specifying how the app should behave in its activity code. But there are still lots of things you donât yet know about how activities function.
How long does an activity live for? What happens when your activity disappears from the screen? Is it still running? Is it still in memory? And what happens if your app gets interrupted by an incoming phone call?
You want to be able to control the behavior of your activities in a whole range of different circumstances, so weâre going to take a closer look at how activities work under the hood. Weâll look at some common ways in which your apps can break, and how you can fix them using the activity lifecycle methods ...
Get Head First Android Development, 3rd Edition 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.