Activity and Fragment Lifecycles and Orientation Changes

后端 未结 2 548
失恋的感觉
失恋的感觉 2021-02-05 16:26

I have been having very odd issues with Fragments and orientation changes that have been causing force closes and not following a logical pattern.

I created

2条回答
  •  感动是毒
    2021-02-05 16:55

    This happens because the activity calls onSaveInstanceState(Bundle) before being destroyed. By default, the activity is saving the states of its fragments in this method.

    Later, when the activity is re-created, the old fragments are re-created in the activity onCreate(Bundle savedInstanceState) method.

    You might want to check the source code here and here to better understand this behaviour.

提交回复
热议问题