ncapdevi / FragNav

An Android library for managing multiple stacks of fragments
1.5k stars 220 forks source link

showDialogFragment: fragment that does not belong to this FragmentManager! #224

Open solareye opened 4 years ago

solareye commented 4 years ago

I have FragNavController in my activity. When I call showDialogFragment like fun BaseFragment.showDialogFragment( bottomFragment: BottomSheetDialogFragment, requestCode: Int = 0 ) { bottomFragment.setTargetFragment(this, requestCode) this.baseActivity().fragNav?.showDialogFragment(bottomFragment) } app crashed with

fragment that does not belong to this FragmentManager!

ts14ic commented 4 years ago

Reproduced same (or similar issue?) with these steps:

  1. Open fragment A
  2. Open fragment B on top of A
  3. Add a dialog in fragment B
  4. Click a button on the dialog dismissing it and pop fragment B as a result
  5. Try to add a new dialog - doesn't matter where, the fragment manager is "corrupted" at this point
  6. Exception thrown

The way I fixed it - where I pop fragment B, I also added a call to clearDialogFragment BEFORE popping B.

p.s. The Exception I received was:

07-20 19:04:13.399 5688-5688/***.*** E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ***.***, PID: 5688
    java.lang.IllegalStateException: Fragment ConfirmDialog{b5bf4bc (6e206fd7-1e27-4cee-ab7d-aa00101dbbac)} not associated with a fragment manager.
        at androidx.fragment.app.Fragment.requireFragmentManager(Fragment.java:910)
        at androidx.fragment.app.DialogFragment.dismissInternal(DialogFragment.java:245)
        at androidx.fragment.app.DialogFragment.dismiss(DialogFragment.java:202)
        at com.ncapdevi.fragnav.FragNavController.clearDialogFragment(FragNavController.kt:464)
        at com.ncapdevi.fragnav.FragNavController.showDialogFragment(FragNavController.kt:483)
        at ***.***.common.fragments.ScreenNavigator.addDialog(ScreenNavigator.kt:49)
        at ***.***.***.***SomeFragment***.onPop(***SomeFragment***.kt:97)
        at ***.***.common.fragments.ScreenNavigator.pop(ScreenNavigator.kt:61)
        at ***.***.common.activities.BaseActivity.onBackPressed(BaseActivity.kt:28)
        at ***.***.common.activities.MainActivity$onStart$1.onClick(MainActivity.kt:39)
        at android.view.View.performClick(View.java:5198)
        at android.view.View$PerformClick.run(View.java:21147)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)