Replacing a Fragment with itself does not show anything

后端 未结 4 733
猫巷女王i
猫巷女王i 2021-01-12 20:19

I\'m trying to decide and show a fragment in activity\'s onResume method, but in case a previously added fragment is chosen again, then the activity goes bl

4条回答
  •  终归单人心
    2021-01-12 20:47

    You can't replace a fragment with itself. The first half of a replace is a removal of the previous fragment at that id. Once a fragment is removed it can no longer be added or used by the fragment manager (so the add portion of the replace will not work properly).

    Depending on your use case, you have two options:

    1. Create a new fragment instead of reusing the existing instance
    2. Use some other method to see if its necessary to replace your fragment

    Finally, you probably don't need to call executePendingTransactions.

提交回复
热议问题