What is the Android activity lifecycle?

In short
The Android activity lifecycle is the set of states an activity moves through as a user opens, leaves, and returns to a screen. The system calls callback methods at each change, so your code can save work, release resources, and restore the screen at the right moment.
The basic idea
An activity is one screen of an Android app. The user can open it, switch to another app, rotate the phone, or come back later. Each of these actions changes the activity's state. Android tracks those states and calls a method on your activity whenever one changes. These methods are called callbacks, and together they form the activity lifecycle.
The Activity class provides six core callbacks: onCreate, onStart, onResume, onPause, onStop, and onDestroy. The system calls each one as the activity enters a new state. You do not call them yourself. You override the ones you need and put work in them that fits that moment.
The official documentation describes the lifecycle as a way to plan what your app does when the user leaves and comes back. A video player is a good example. It can pause playback and close a network connection when the user switches apps, then reconnect and resume from the same spot when the user returns.
What each callback is for
onCreate runs once, when the system first creates the activity. This is where you set up the screen, bind data to views or lists, and read the savedInstanceState bundle. That bundle is null if the activity has never existed before. Otherwise it holds state you saved earlier.
onStart runs when the activity becomes visible. The screen is shown, but the user may not be able to interact with it yet. Code that keeps the UI up to date can start here.
onResume runs when the activity reaches the foreground and the user can interact with it. This is the state where the app is active. It stays there until something takes focus away, such as an incoming phone call, a move to another activity, or the screen turning off. Start things here that must run only while the screen is visible, such as a camera preview.
onPause runs when another activity or an interruption takes focus. The activity may still be partly visible, for example in multi-window mode. Release things that should not keep running while the user cannot interact with you, such as the camera. Keep this method quick, because the next activity waits for it.
onStop runs when the activity is no longer visible. This is a good place to stop heavier work, release resources you do not need in the background, or save data.
onDestroy runs before the activity is removed. It can happen because the user closed the screen, or because the system is recreating the activity, for example after a rotation. Clean up anything that is still held here.
A simple example
The next example shows the kind of work that belongs in each method. It assumes a player object with play and pause methods.
class PlayerActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Build the layout and load data once. } override fun onResume() { super.onResume() player.play() } override fun onPause() { super.onPause() player.pause() } }
Here, playback starts when the screen is interactive and pauses when the user is pulled away. The same pattern works for sensors, cameras, and location updates. Start them in onResume and stop them in onPause, so they do not run when nobody can see the screen.
Common mistakes
A frequent mistake is putting slow work in onCreate or onResume. Those callbacks run on the main thread, so long tasks make the interface feel frozen. Move network calls and file reads to background work and update the screen when the result arrives.
Another mistake is acquiring a resource in onResume and forgetting to release it in onPause. Each acquire needs a matching release, or the app keeps using memory, battery, or the camera after the user has left.
Do not assume that onDestroy always runs. The system can end the process without calling it. For that reason, save important user data when the activity stops, not only when it is destroyed.
Finally, remember that onCreate runs again after a rotation, because the activity is recreated. If you keep UI state only in fields, it is lost. Save it in the saved state bundle, or keep it in a ViewModel, so it survives the change.
Compose and the lifecycle
If your screen is built with Jetpack Compose, you rarely need to put logic directly in these callbacks. Compose offers lifecycle-aware tools. For example, collectAsStateWithLifecycle collects a flow only while the UI is started, and it stops when the app goes to the background. This keeps work running only when the user can see it.
Alternatives and related ideas
If you want the same behavior without writing it in the activity, you can make a separate component lifecycle-aware. That component receives the lifecycle events itself, which keeps the activity smaller and the logic easier to test. Architecture components and a ViewModel can also hold data across configuration changes, so you do not need to rebuild it each time.
The lifecycle is the foundation for these choices. Once you know which state your code runs in, the right callback is easy to pick.
FAQ
What is the difference between onPause and onStop?
onPause runs when the activity loses focus but may still be partly visible, such as in multi-window mode. onStop runs when the activity is no longer visible to the user.
Why does my activity restart when I rotate the phone?
Rotation changes the configuration, so the system destroys and recreates the activity. The lifecycle callbacks run again, which is why saved state and a ViewModel are useful.
Can I rely on onDestroy to save user data?
No. The system can stop a process without calling onDestroy. Save important data earlier, typically in onStop or when the user leaves the screen.
Should I start network requests in onCreate?
You can start them, but do not block the main thread. Run network calls in background work and update the screen when the result arrives.
Sources
This page is based on the official documentation below. Read it for full detail.
Android activity lifecycle — official documentation ↗