Lifecycle order: A opens B

Lifecycle and app components Mid-level Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Order the steps

A starts an opaque Activity B. Put the callbacks in order.

  • B.onCreate
  • B.onStart
  • B.onResume
  • A.onPause
  • A.onStop
Hint 1 of 1

A has to give up the foreground before B can take it.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: D A B C E

  1. A.onPause A gives up the foreground first.
  2. B.onCreate B is created.
  3. B.onStart B becomes visible.
  4. B.onResume B is in front.
  5. A.onStop Only now is A hidden, because B covers it.
Three scenarios: A opens opaque B, A opens transparent B, and Back from B. One combined callback list with an activity chip.

Illustrative, based on Compose and Android rules; not a device recording

Text version

A opens B

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

A opens transparent B

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

Back from opaque B

  1. B onPause
  2. A onRestart
  3. A onStart
  4. A onResume
  5. B onStop
  6. B onDestroy
What survives
StateA opens BA opens transparent BBack from opaque B
local var✓ kept✓ kept✓ kept
remember✓ kept✓ kept✓ kept
rememberSaveable✓ kept✓ kept✓ kept
ViewModel✓ kept✓ kept✓ kept
SavedStateHandle✓ kept✓ kept✓ kept
Room / disk✓ kept✓ kept✓ kept

30-second answer

A pauses first, then B is created, started and resumed, and only then is A stopped: A.onPause, B.onCreate, B.onStart, B.onResume, A.onStop. A is paused before B appears so it can release the foreground, and stopped after B is visible. If B is transparent or dialog-themed, A stays visible, so it is paused but never stopped.

Practise saying it · 40 s. No recording, just a timer

Explain the A→B callback order.

Say your answer out loud, then check which of these points you covered:

  • A.onPause first
  • B create, start, resume
  • A.onStop last
  • Transparent B: A is never stopped

Deep dive

Pressing Back in B: B.onPause, A.onRestart, A.onStart, A.onResume, B.onStop, B.onDestroy.

Because A.onStop comes after B.onResume, saving data in A.onPause can slow B's launch.

With a transparent B, Back gives A.onResume without onRestart/onStart, because A never stopped.

The exact interleaving is what the system does today; don't write code that depends on B's callbacks running before A's onStop.

Common mistakes

  • Saying A is stopped before B is created.
  • Expecting A.onStop when B is a dialog-themed Activity.
  • Doing heavy saves in A.onPause.

Senior take & follow-ups

Get the order right, then add the transparent case. That's exactly what interviewers check.

Follow-up questions

Think of your answer first, then open the hint.

  1. What does A get when you press Back in a transparent B?

    Show hint

    Only onResume.

  2. Why does A.onStop wait for B.onResume?

    Show hint

    A must stay visible until B can draw.

Suggest a fix if something here is wrong or out of date.