ichernob
ichernob

Reputation: 367

Lifecycle callback order with "don't keep activities" mode

I'm trying to find any information about guaranteed lifecycle callbacks order (interested only in onCreate, onResume, onPause) for the following scenario:

  1. Don't keep activities mode is enabled.
  2. Activity A starts Activity B (dialog activity) and becomes partially obscured.
  3. User presses Home button.
  4. Both activities are destroyed.
  5. User navigates back to app.

So, what is the guaranteed lifecycle callbacks execution order after steps (3), (5)?

Upvotes: 1

Views: 753

Answers (1)

azizbekian
azizbekian

Reputation: 62189

So, what is the guaranteed lifecycle callbacks execution order after steps (3), (5)?

After step 3:

  • onStop() is guaranteed to be called
  • onDestroy() is not guaranteed.

After step 5:

  • onCreate()
  • onStart()
  • onRestoreInstanceState()
  • onResume()

All of these are guaranteed to be called.


I've logged lifecycle callbacks, and here's the output.

Activity A starts Activity B

  • A pause
  • B create
  • B start
  • B resume
  • A saveInstanceState

Home button pressed

  • B pause
  • A stop
  • B saveInstanceState

User navigates back to app

  • A create
  • A start
  • A restoreInstanceState
  • A resume
  • A pause
  • B start
  • B resume

Note:

  • ActivityB has Theme.AppCompat.Dialog as theme
  • Don't keep activities mode is turned on
  • Running on Nexus 4 emulator, API 21

Upvotes: 1

Related Questions