Can you walk through the Activity lifecycle?
Explain Activity lifecycle states, callback responsibilities, and modern lifecycle-aware patterns.
What the interviewer is testing
The interviewer is checking whether you understand what each lifecycle state means and can place work according to visibility, user interaction, and resource ownership.
A strong answer goes beyond reciting callback order. It explains where setup and cleanup belong, recognises that configuration changes create a new Activity instance, and avoids treating lifecycle callbacks as storage for business logic.
❌ Common mistake
If they ask you to elaborate
Think of each callback as Android notifying you that the Activity has entered a different state. The callback names matter, but understanding the state transition and the responsibility that comes with it is what interviewers are really assessing.
| Callback | Activity state | Typical responsibility |
|---|---|---|
onCreate() | Instance is being created | Inflate or compose the UI, restore lightweight UI state, obtain the ViewModel, configure navigation |
onStart() | Visible | Start work that should run while the UI is visible; begin lifecycle-aware observation |
onResume() | Foreground and interactive | Acquire exclusive foreground resources such as camera input, sensors, or active interaction |
onPause() | Losing foreground focus | Pause exclusive work and commit small, fast UI changes; do not perform slow blocking work |
onStop() | No longer visible | Stop visibility-bound work and release heavier resources that are not needed in the background |
onDestroy() | This Activity instance is being destroyed | Release resources owned for the full instance lifetime; distinguish finishing from recreation when relevant |
The normal launch path is:
onCreate() → onStart() → onResume()
When another screen fully covers the Activity, it usually moves through:
onPause() → onStop()
If the user returns, the existing instance normally receives:
onRestart() → onStart() → onResume()
If the Activity finishes, it proceeds toward onDestroy(). The exact path depends on what happens: a partially covering window may trigger onPause() without onStop(), while multi-window mode means an Activity can remain visible without being the currently resumed Activity.
A useful rule is to acquire and release resources symmetrically. Work started in onStart() should normally stop in onStop(); work started in onResume() should normally stop in onPause().
A configuration change, such as a rotation or window-size change, usually destroys the current Activity instance and creates a new one. A ViewModel can retain screen state across that recreation, but it does not survive system-initiated process death. Restorable UI state belongs in saved state APIs, while durable application data belongs in persistent storage.
Code example
class OrdersActivity : AppCompatActivity(R.layout.activity_orders) {
private val viewModel: OrdersViewModel by viewModels()
private lateinit var locationUpdates: LocationUpdates
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState.collect(::render)
}
}
}
override fun onStart() {
super.onStart()
locationUpdates.start()
}
override fun onStop() {
locationUpdates.stop()
super.onStop()
}
private fun render(state: OrdersUiState) {
// Render the latest state into the existing view hierarchy.
}
}The ViewModel owns screen state instead of the Activity instance. repeatOnLifecycle collects only while the lifecycle is at least STARTED, cancels the collection when the Activity stops, and restarts it when the Activity becomes visible again.
The location resource is acquired in onStart() and released in onStop() because this example needs updates only while the screen is visible. A resource needed exclusively while the user can interact would instead be paired across onResume() and onPause().
Follow-up questions
What separates a senior answer
Key takeaways
Learn more
What is the difference between an Activity and a Fragment?
Explain the different responsibilities of Activities and Fragments in modern Android.
Can you describe the Fragment lifecycle and Fragment view lifecycle?
Explain why a Fragment and its view have different lifetimes, and how that affects UI work and cleanup.