Here is my code to show DialogFragment from another fragment:
override fun showDialog(dialog: DialogFragment, tag: String?) {
val fragmentManager = fragment.childFragmentManager
if (tag != null) {
fragmentManager.executePendingTransactions()
val fragment = fragmentManager.findFragmentByTag(tag)
if (fragment != null) {
return
}
}
dialog.show(fragmentManager, tag)
}
Everything works well, the dialog is displayed as it should.
However, I observe the following problem:
Caused by: java.lang.IllegalStateException: FragmentManager is already executing transactions
at androidx.fragment.app.FragmentManager.ensureExecReady(FragmentManager.java:1636)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1695)
at androidx.fragment.app.FragmentManager.executePendingTransactions(FragmentManager.java:564)
at *******************.showDialog()
Suppose after a network request a dialog was shown through which the user went to the system settings, after returning to the screen of my application, the network request is sent again and the dialog is shown again. And as far as I understand, the fragment transaction is ongoing, and at the same time it tries to execute new transaction in order to show DialogFragment.
As a solution to the problem, I found the use childFragmentManager
. But that doesn't help me. Please help me find a possible solution to the problem.