How to pass data from a fragment hosting `Fragment...
# android
k
How to pass data from a fragment hosting
FragmentContainerView
to its child fragments (which are part of the navigation graph used by FragmentContainerView)
g
Have you checked the new Fragment documentation on this topic? https://developer.android.com/guide/fragments/communicate
k
Yes.. though I called them child fragements... it doesn't seem to be treated like that, I tried many options from this page, nothing worked.
m
Do you have a layout defined that has the fragment as a child of the parent in the XML as well? If you do not, then I've seen
getParentFragment
return null and you don't get your viewmodel. It's possible you have something else going on, but there's definitely a few ways to do this.
k
I changed the way to tackle my problem.. Let me first define my system. Basically I've multi-backstack navigation system with further nested nav graphs on some pages. I need a way to Navigate across multiple stacks and to even deeply nested fragments. Like I want to be able to Navigate from Tab A to Tab B's destination's nested graph's first page. Is it even possible? I'm getting into cyclical dependency issues due to these requirements
m
so, without seeing your nav graph and your source layout, I'm not sure what to advise here; I believe what you're trying to do is possible, but I also know it would involve a varying amount of boilerplate, depending on exactly how complicated your nav graph might be. depending on whether you're sharing data between the fragments, you might also want to consider defining a base fragment and extending - again, this is very largely dependent on what your nav graph looks like. I would recommend maybe commenting some things out and starting with a simple version of the nav graph and gradually add complexity, watching for where it breaks down - that may help you find the problem.
k
I've 4 navigation tabs, each has its own nav graph. So there's one navHostFragment but multiple NavControllers operating on it based on the currently selected tab. Do you want me to share all 4 of them?