0

I'm using navigation to navigate between fragments.

And I have a DialogFragment, it can called from from many fragment like this:

 val dialog = FragmentDialog
 dialog.show(childFragmentManager, "home_fragment")

And I want to know dialogfragment called by which fragment

I tried with FragmentManager.backStackEntryCount but it's seem doesn't work

Can I have a advice for this problem ???

ninhnau19
  • 695
  • 1
  • 3
  • 16

1 Answers1

0

There are multiple ways to do this ..

  1. You can just Pass a key in Bundle to your DialogFragment to check which Fragment opened it ..

  2. If your Dialog fragment a attached to a fragment in each case you can just use getParentFragment() . getParentFragment() will return the instance of that fragment. If its attached to activity then getParentFragment() will be null so watch out for this case also .

  3. you can also use getTag() from where it was open byt passing different tags to transaction .

ADM
  • 20,406
  • 11
  • 52
  • 83