Activity Lifecycle Quiz

ANDROID › Lifecycle

On device rotation, what is the callback sequence for the existing activity instance?

Answer: onPause, onStop, onDestroy

Rotation is a configuration change: the activity is torn down (onPause, onStop, onDestroy) with instance state saved, then a fresh instance is created and restored.

The user presses the Home button. Which statement is true?

Answer: onPause then onStop run, onSaveInstanceState may fire, and it can be killed

Home sends the activity to the background (onPause then onStop); state is saved so it can be restored if the process is later reclaimed, but the instance is kept until then.

You call finish() inside onCreate(). What runs next?

Answer: onDestroy runs immediately, skipping all the other callbacks

This is the documented exception: finish() in onCreate causes onDestroy to run directly without onStart, onResume, onPause, or onStop.

In multi-window mode an activity loses focus to the other window but stays fully visible. Its state is:

Answer: Paused; onPause is called, but the activity can still show

Only one window holds focus at a time; the unfocused activity is Paused yet may remain visible, which is exactly why UI teardown belongs in onStop, not onPause.

Which scenario passes a non-null savedInstanceState Bundle to onCreate()?

Answer: Recreation after a config change or process death

The Bundle is populated only when the system saved state to recreate the activity (config change or process death). Back discards state, and a merely stopped activity is not recreated.

Activity A starts a full-screen opaque Activity B. What is the correct interleaving of callbacks?

Answer: A.onPause, B.onCreate, B.onStart, B.onResume, A.onStop

A pauses first, B comes fully up (create, start, resume), and only then does A stop once it is no longer visible behind B.

An activity with launchMode="singleTop" is already at the top of the task and is launched again. Which callback receives the new intent?

Answer: onNewIntent on the existing instance; onCreate is skipped

singleTop reuses the existing top instance and delivers the intent via onNewIntent (typically onPause, onNewIntent, onResume) rather than creating a new instance with onCreate.

On API 29+ several activities can be RESUMED at once. Which callback tells an activity it now owns exclusive singleton hardware like the camera, and how should it react?

Answer: onTopResumedActivityChanged(true): take the camera; release it on false

onTopResumedActivityChanged(Boolean) was added for multi-resume so an activity learns when it becomes the single top-focused one; acquire the exclusive resource on true and release on false.

Inside onDestroy(), how do you reliably distinguish a permanent finish from a transient destroy that will be followed by recreation?

Answer: Call isFinishing(): true means a real finish, false a recreation

isFinishing() returns true only when the activity is genuinely finishing; on a configuration change it returns false because the instance is being destroyed only to be recreated.

Activity A launches Activity B, but B uses a translucent (dialog-style) theme so A stays partly visible behind it. What happens to A?

Answer: A receives onPause but not onStop, since A remains visible behind B

onStop fires only when an activity becomes fully invisible; a translucent activity does not cover A, so A stops at Paused and onStop is not called.

For an app targeting a modern Android version (API 28+), when is onSaveInstanceState() invoked relative to onStop()?

Answer: After onStop(), since Android P changed the guaranteed order

Since apps targeting Android P (API 28), onSaveInstanceState is guaranteed to run after onStop; on older targets it ran before onStop with no firm ordering against onPause.

The user navigates from a stopped (but not destroyed) Activity back to it via Recents. What callback sequence does that instance receive?

Answer: onRestart, onStart, onResume, with no onCreate

A stopped instance that was never destroyed re-enters the foreground via onRestart then onStart then onResume; onCreate is skipped because no new instance is built and no Bundle is involved.

A ViewModel holds UI state. The app is backgrounded and the OS later kills the process to reclaim memory; the user then returns. What is restored?

Answer: Only state from onSaveInstanceState/SavedStateHandle; the ViewModel is new

ViewModels survive configuration changes but not process death; after the process is recreated only the saved-state Bundle (e.g. via SavedStateHandle) is restored, and a fresh ViewModel is built.

Back to Activity Lifecycle