xxv / android-lifecycle

A diagram of the Android Activity / Fragment lifecycle
5.26k stars 681 forks source link

onSaveInstnceState will not always be called #7

Open ndori opened 10 years ago

ndori commented 10 years ago

http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState%28android.os.Bundle%29

in a nutshell, it won't always get called, for fragment pop it in and out from the backstack won't call it.

it will only get called if the activity is going to be destroyed and it knows about it in advance... (so orientation change - yes, opening another app then closing it - no)

xxv commented 10 years ago

Good point. Perhaps it could have a better note about it not being a standard lifecycle method.

slightfoot commented 8 years ago

A point to mention is how the behaviour changes with onSaveInstanceState() and setRetainedInstance(). See https://stackoverflow.com/questions/13420448/how-i-can-break-things-with-fragments-with-setretaininstancetrue-and-adding-th