





















































MobilePro #188: Android's Activity Lifecycle—A Sneak Peek Behind the Curtain
Thinking about upgrading to Apache Airflow® 3? You’ll get powerful new features like a modernized UI, event-based scheduling, and streamlined backfills. Quick Notes: Airflow 3 Tips & Code Snippets is a concise, code-filled guide to help you start developing DAGs in Airflow 3 today.
You’ll learn:
Hi ,
Welcome to the 188th edition of MobilePro!
Think of your Android app like a stage play. When the curtain rises, the actors (your activities) step into the spotlight, ready to perform. Sometimes they pause mid-scene while the spotlight shifts, sometimes they step into the wings to wait for their cue, and eventually, they exit the stage entirely. The audience may not notice all the behind-the-scenes work, but as the developer, you’re the stage manager making sure the transitions are smooth and the show goes on without a hitch.
So, every time your app is opened, backgrounded, resumed, or closed, it passes through well-defined stages. Android provides callback methods—like cues in a script—that let you know when it’s time to set the scene, save the current state, or clean things up. Mastering these callbacks means your app won’t drop the ball when a user takes a call, rotates their screen, or swipes it away from the task list.
In this article, we’ll break down the key lifecycle callbacks step by step, showing you how they work and how you can use them to keep your apps running smoothly. This is excerpted from the book How to Build Android Applications with Kotlin, written by Alex Forrester, Eran Boudjnah, Alexandru Dumbravan, and Jomar Tigcal.
Before we jump in though, let's take a quick look at last week's highlights:
Senior Android Developer
NatWest Group
Director
Mitteloupe Limited
Principal Android Engineer
Nutmeg
Lecturer
De La Salle University
Imagine you’re using your favorite app, scrolling through a feed, when suddenly you get a phone call. The app disappears into the background, but when you return a few minutes later, everything is right where you left it. Or perhaps you rotate your phone, and the screen smoothly reorients itself without losing sight of what was onscreen. While regular users may not be aware that these little moments of continuity don’t happen by accident; you are likely to know that this is a result of Android’s activity lifecycle.
For every one of these steps, there is a callback that your activity can use to perform actions such as creating and changing the display, saving data when your app has been put into the background, and then restoring that data after your app comes back into the foreground.
These callbacks are made on the parent activity, and it’s up to you to decide whether you need to implement them in your own activity to take any corresponding action. Each of these callback functions has the override keyword. The override keyword in Kotlin means that either this function is providing an implementation of an interface or an abstract method; or, in the case of your activity here, which is a subclass, it is providing the implementation that will override its parent.
Now that you know how the activity lifecycle works in general, let’s first dive into the flow of callbacks and events, which is illustrated in the following diagram:
Now that you’ve taken in this flow of events, let us go into further detail about the principal callbacks you will work with in order, from creating an activity to the activity being destroyed:
At the end of the day, the activity lifecycle is like stage directions for your app. Each callback tells you when to set the scene, when to pause, and when to take a bow. Master these cues, and your app won’t just run; it’ll deliver a performance worth a standing ovation.
If you want to learn more about Android and its functions, then How to Build Android Applications with Kotlin is the book for you!