Android's Activity Lifecycle: A Screen's Journey

Think of an Activity's lifecycle as a stage play's script. Methods like onCreate() and onPause() are cues for your app screen to set up, appear, or hide. This manages state during interruptions like phone calls.
Why it exists
Android runs on resource-constrained devices where the OS must aggressively manage memory. It can terminate background apps at any time. The Activity Lifecycle provides a predictable contract for your app to save its state before being killed and restore it gracefully when the user returns, ensuring a seamless experience despite system-level interruptions.
The mental model
Think of an Activity as a single screen in your app. Its lifecycle is a state machine with a series of states: Created, Started, Resumed, Paused, Stopped, and Destroyed. The Android OS pushes your Activity through these states in response to user actions and system events. You don't control the transitions, but you can react to them by overriding callback methods like onCreate() or onPause().
How it works
When an Activity launches, the OS calls a sequence of methods: onCreate() for one-time setup, then onStart() to make it visible, and finally onResume() to bring it to the foreground and make it interactive. If another Activity partially obscures it (like a permission dialog), onPause() is called. If the user navigates away entirely, onPause() and then onStop() are called. If the user returns, the OS calls onRestart(), onStart(), and onResume(). If the app is finished by the user or killed by the system, onPause(), onStop(), and finally onDestroy() are called to clean up resources.
When to use it
You use the lifecycle constantly; it's not optional. The key is overriding the right method for the right job. Use onCreate() for essential, one-time initializations like setting the layout view and creating ViewModels. Use onStart() and onStop() to manage resources that are only needed when the UI is visible, like registering a broadcast receiver. Use onResume() and onPause() for tasks that require exclusive access, like using the camera.
When not to use it
Do not use lifecycle callbacks to store user data or complex UI state directly in Activity properties. When the screen rotates, the Activity is destroyed and recreated by default, wiping out that data. Instead, use a ViewModel, which is designed to survive these configuration changes. Crucially, never perform long-running operations like network requests or heavy database queries in any lifecycle callback on the main thread, as this will freeze the app and trigger an 'Application Not Responding' (ANR) error.
One canonical example
Consider a video player app. In onCreate(), you would initialize the player library. In onStart(), you might prepare the video source. In onResume(), you begin playback. If a phone call interrupts the app, onPause() is called, and you must pause the video. When the user returns after the call, onResume() is called again, and you resume playback. When the user navigates to another screen, onStop() is called, and you should release the player's hardware resources. Finally, in onDestroy(), you clean up any remaining connections or listeners.
Interview question
What is the primary reason Android employs an Activity Lifecycle?
- a.To prevent the operating system from ever terminating background applications.
- b.To ensure applications remain active and visible to the user at all times.
- c.To allow developers to manually trigger screen transitions and data saving.
- d.To provide a predictable mechanism for apps to manage resources and state during system-level interruptions.Correct
Why? this is the answer
The Activity Lifecycle exists to provide a predictable contract for apps to manage their state and resources, especially when the OS needs to reclaim memory by terminating background apps. Option D directly reflects this purpose. Option A is incorrect because the OS can and does terminate background applications; the lifecycle helps apps gracefully handle this.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
- #android
- #kotlin
- #activity
- #lifecycle
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles