6.3.3. Activity and Fragment Lifecycle Methods

When a Fragment is attached to an Activity as we did in Chapter 5 and will do in this chapter, its lifecycle is tied to that of its parent Activity. There are six Activity lifecycle methods that have corresponding Fragment lifecycle methods—onCreate, onStart, on-Resume, onPause, onStop and onDestroy. When the system calls these methods on an Activity, it will also call these corresponding methods (and potentially other Fragment lifecycle methods) on all of the Activity’s attached Fragments.

This app uses Fragment lifecycle methods onPause and onDestroy. An Activity’s onPause method is called when another Activity receives the focus, which pauses the one that loses the focus and sends it to the background. ...

Get Android™ How to Program, Second 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.