Activity Lifecycle Questions with Answers

16 practice questions on Activity Lifecycle (Android (Kotlin & Compose)) with answers and step-by-step solutions. Try 10 samples below, then practise all 16 free in the AptiNest app.

Sample questions

Question 1Easy

Which callback means the Activity is in the foreground and interacting with the user?

  1. onCreate()
  2. onResume()
  3. onDestroy()
  4. onStop()

Answer: B. onResume()

Explanation

After onResume the Activity is in the RESUMED state.

Step-by-step solution

  1. onCreate sets up; onStart makes it visible.
  2. onResume moves it to the RESUMED state.
  3. In RESUMED the Activity is in the foreground and receives user input.

Why the other options are wrong

  • A. After onCreate the Activity is not yet visible.
  • C. onDestroy is the end of the lifecycle.
  • D. onStop means the Activity is no longer visible.

Tip: Resumed = foreground + interactive.

Question 2Easy

Which callback is the final one before an Activity is destroyed?

  1. onStop()
  2. onPause()
  3. onRestart()
  4. onDestroy()

Answer: D. onDestroy()

Explanation

onDestroy runs when the Activity finishes or is destroyed for a configuration change.

Step-by-step solution

  1. The teardown order is onPause, onStop, onDestroy.
  2. onDestroy is the last callback.
  3. After it, the Activity instance is gone.

Why the other options are wrong

  • A. onStop comes before onDestroy.
  • B. onPause comes before onStop.
  • C. onRestart is called when coming back, not when ending.

Tip: Save important data in onStop, not onDestroy.

Question 3Easy

Every Activity must be declared in:

  1. AndroidManifest.xml
  2. settings.gradle
  3. strings.xml
  4. build.gradle

Answer: A. AndroidManifest.xml

Explanation

Undeclared activities cannot be started.

Step-by-step solution

  1. The system learns about app components from AndroidManifest.xml.
  2. Each Activity needs an <activity> entry there.
  3. Starting an undeclared Activity throws ActivityNotFoundException.

Why the other options are wrong

  • B. settings.gradle lists project modules.
  • C. strings.xml holds text resources.
  • D. build.gradle configures the build and dependencies.

Tip: Component not declared = not found.

Question 4Easy

ANR (Application Not Responding) occurs when:

  1. The app uses too much storage
  2. The network is offline
  3. A permission is denied
  4. The main thread is blocked

Answer: D. The main thread is blocked

Explanation

Heavy work must run off the main thread to keep the UI responsive.

Step-by-step solution

  1. The main thread must keep handling input events and drawing.
  2. If it is blocked for about 5 seconds during input, the system detects it.
  3. Android then shows the ANR dialog.

Why the other options are wrong

  • A. Running out of storage causes write errors, not ANR.
  • B. Being offline makes network calls fail; it does not block the UI by itself.
  • C. A denied permission returns a result; it does not freeze the app.

Tip: ANR = blocked main thread (about 5 s for input).

Question 5Medium

The user presses Home while your Activity is visible. Which callbacks are typically called?

  1. onPause() then onStop()
  2. onDestroy() only
  3. onPause() only
  4. onStop() then onPause()

Answer: A. onPause() then onStop()

Explanation

The Activity is no longer visible but stays in memory, so it is not destroyed.

Step-by-step solution

  1. Pressing Home makes the Activity lose focus, so onPause() runs.
  2. It is then fully hidden, so onStop() runs.
  3. It is not destroyed; it stays in the back stack.

Why the other options are wrong

  • B. Home does not destroy the Activity; it can be resumed later.
  • C. onPause alone happens when the Activity is only partly hidden.
  • D. The order is always pause before stop.

Tip: Going away: Pause then Stop. Coming back: Restart, Start, Resume.

Question 6Medium

By default, what happens to an Activity when the screen is rotated?

  1. Only onPause is called
  2. It is recreated
  3. Nothing; it only redraws
  4. The app is killed

Answer: B. It is recreated

Explanation

A configuration change recreates the Activity; ViewModels and saved state carry data across.

Step-by-step solution

  1. Rotation is a configuration change.
  2. By default Android destroys the Activity and creates it again with the new configuration.
  3. ViewModel and saved instance state keep data across the recreation.

Why the other options are wrong

  • A. onPause is followed by onStop and onDestroy during recreation.
  • C. It is a full recreation, not just a redraw.
  • D. Only the Activity is recreated; the app process keeps running.

Tip: Rotation = destroy + recreate; ViewModel survives it.

Question 7Medium

A semi-transparent dialog-style Activity opens on top of yours. Your Activity is partly visible. Which state is it in?

  1. Destroyed
  2. Created only
  3. Resumed
  4. Paused

Answer: D. Paused

Explanation

Partially visible but not in focus means onPause has been called without onStop.

Step-by-step solution

  1. A partly transparent Activity on top takes focus.
  2. Your Activity is still partly visible but cannot receive input.
  3. So it is paused, not stopped.

Why the other options are wrong

  • A. Nothing destroys it; it is still on screen.
  • B. It has already gone through start and resume.
  • C. Resumed means in focus and interactive, which it no longer is.

Tip: Partly visible = Paused; fully hidden = Stopped.

Question 8Medium

In which lifecycle state should a camera preview or sensor listener usually be released to save battery?

  1. Only in onCreate
  2. Never
  3. Only when the app is uninstalled
  4. When it pauses or stops

Answer: D. When it pauses or stops

Explanation

Release resources when not visible and reacquire them when resumed; lifecycle-aware components help.

Step-by-step solution

  1. Camera and sensors use battery while active.
  2. When the Activity is not visible or not in focus, nobody needs them.
  3. So release them in onPause or onStop and get them again in onResume or onStart.

Why the other options are wrong

  • A. onCreate is for setup, not release.
  • B. Holding the camera forever wastes battery and blocks other apps.
  • C. Waiting until uninstall means holding the resource the whole time.

Tip: Pair them: acquire in onStart/onResume, release in onStop/onPause.

Question 9Hard

Activity A starts Activity B. In what order do these run?

  1. A.onPause, B.onCreate, B.onStart, B.onResume, A.onStop
  2. A.onStop, A.onPause, B.onCreate, B.onStart, B.onResume
  3. B.onCreate, B.onStart, B.onResume, A.onPause, A.onStop
  4. A.onPause, A.onStop, B.onCreate, B.onStart, B.onResume

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

Explanation

A pauses first, B becomes visible and resumed, then A stops once it is no longer visible.

Step-by-step solution

  1. A.onPause() runs first, so B can come to the front.
  2. B.onCreate(), B.onStart(), B.onResume() run; B is now interactive.
  3. A is now fully hidden, so A.onStop() runs last.

Why the other options are wrong

  • B. onStop never comes before onPause.
  • C. A must pause before B is created.
  • D. A stops only after B is visible, not before B is created.

Tip: Keep onPause light; the next Activity waits for it.

Question 10Hard

A Compose screen collects a flow with collectAsStateWithLifecycle(). The user switches to another app. What happens to collection?

  1. It pauses
  2. The app crashes
  3. The flow is deleted
  4. It continues forever

Answer: A. It pauses

Explanation

The default minActiveState is STARTED, so collection pauses in the background and resumes on return.

Step-by-step solution

  1. collectAsStateWithLifecycle collects only while the lifecycle is at least STARTED by default.
  2. Switching apps stops the Activity, dropping below STARTED.
  3. Collection pauses and restarts when the user returns.

Why the other options are wrong

  • B. Nothing crashes; collection simply stops.
  • C. The flow is not deleted; it is collected again on return.
  • D. Plain collectAsState keeps collecting; the lifecycle-aware version does not.

Tip: Use collectAsStateWithLifecycle, not collectAsState, for ViewModel flows.

Practise all 16 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Android (Kotlin & Compose) topics · All topics