What to determine a Fragment restore upon Activity re-create?

后端 未结 1 1862
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 00:11

For Views having IDs, they will be auto-saved when calling super.onSaveInstanceState(outState);.

For Fragments added to an

相关标签:
1条回答
  • 2021-01-17 00:43

    I had the same problem, you can see it here: After screen rotation, findFragmentById() returns a fragment, even if there's no such ID inside the layout

    The Android Developer Documentation at http://developer.android.com/training/basics/fragments/communicating.html quotes this:

    When a configuration change causes the activity hosting these fragments to restart, its new instance may use a different layout that doesn't include the same fragments as the previous layout. In this case all of the previous fragments will still be instantiated and running in the new instance. However, any that are no longer associated with a tag in the view hierarchy will not have their content view created and will return false from isInLayout(). (The code here also shows how you can determine if a fragment placed in a container is no longer running in a layout with that container and avoid creating its view hierarchy in that case.)

    That means, we have to check screen orientation than believing in null pointer checks.

    0 讨论(0)
提交回复
热议问题