0

I have the following structure:

Activity
    NavHostFragment (with navigation graph)
        Fragment1
            ChildFragment
        Fragment2
            ChildFragment
        Fragment3

I want to access either Fragment1 or Fragment2 from ChildFragment class, but when I call parentFragment it returns NavHostFragment instead.

I cannot search directly for Fragment1 or Fragment2 by id or tag because as you can see the parent may change so the ChildFragment doesn't really know the id or name of the parent (unless I send it as argument but I'm trying to avoid that).

htafoya
  • 18,261
  • 11
  • 80
  • 104
  • Clearly you do *not* have that structure if `parentFragment` from `ChildFragment` is returning the `NavHostFragment`. How are you creating your `ChildFragment`? Please include your code. – ianhanniballake Jun 02 '22 at 17:23

1 Answers1

0

Ok the problem seems to be that the Fragment1 was adding ChildFragment using parentFragmentManager instead of using childFragmentManager.

htafoya
  • 18,261
  • 11
  • 80
  • 104