Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

Explain the Android Activity lifecycle and why it matters.

An Activity moves through callbacks as the system creates, shows, hides, and destroys it:

  • onCreate() — once, when created. Inflate the layout, initialise the ViewModel, restore saved state.
  • onStart() — becoming visible.
  • onResume() — in the foreground and interactive. Start camera, sensors, animations, and location updates here.
  • onPause() — losing focus but possibly still partly visible. Keep this fast; anything slow delays the next Activity appearing.
  • onStop() — no longer visible. Release heavier resources and unregister listeners.
  • onDestroy() — being destroyed, either by finishing or by a configuration change.

Why it matters so much:

  • Configuration changes destroy and recreate the Activity by default. Rotating the screen runs the whole cycle again, so anything held only in Activity fields is lost. This is why ViewModel exists — it survives configuration changes.
  • Process death is different and harsher. Android can kill a backgrounded app entirely to reclaim memory. ViewModel does not survive that; only onSaveInstanceState or SavedStateHandle does.
  • Leaks come from lifecycle mismatches — a listener registered in onCreate and never unregistered keeps the Activity alive.

Note: Lifecycle-aware components and repeatOnLifecycle for collecting flows are the modern answer, because they tie observation to the lifecycle automatically rather than relying on you remembering to unregister.

All Android interview questions

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as