Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cases when savedInstanceState is NOT null

If I do not explicitly call onSaveInstanceState(), which are possibilities, when savedInstanceState is not null in onCreate?

I see one option, when system recreates my app after crash - then savedInstanceState is not null.

Which are other options?

like image 776
Goltsev Eugene Avatar asked Oct 20 '25 09:10

Goltsev Eugene


1 Answers

Which are possibilities, when savedInstanceState is not null in onCreate()?

  1. System was on shortage of memory, so it killed the process of your app. User navigates to your app, now onCreate() will be called with non-null Bundle.
  2. After configuration change (e.g. orientation change) - onCreate() will be called with non-null Bundle.

If I do not explicitly call onSaveInstanceState()

You shouldn't do that on your own. It's the system that will call activity lifecycle methods and onSavedInstanceState/onRestoreInstanceState.

like image 111
azizbekian Avatar answered Oct 22 '25 01:10

azizbekian