Fragment already added, dialogfragment?

后端 未结 2 1147
温柔的废话
温柔的废话 2021-01-24 10:11

I have a dialogfragment which displays fine but some time when I try to display it I keep getting IllegalStateException

Below is the logcat

         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-24 10:40

    Fragment transactions are asynchronous.

    It is possible that you have two or more calls to this code before the fragment transactions are executed. !selectPlan04Dialog.isVisible() & !selectPlan04Dialog.isAdded() condition is true and show() schedules another fragment transaction to execute later.

    Some options for fixing this:

    • Create a new dialog every time and don't try to reuse an old one
    • Change asynchronous fragment transactions to synchronous with a call to fragment manager executePendingTransactions()

提交回复
热议问题