Skip to content Skip to sidebar Skip to footer

When I Add The Same Fragment To Second Navigation Graph, Don´t Recognize The Action Class

I need to add the same fragment to different navigation graphs. This is piece of code of first graph (mobile_navigation)

Solution 1:

The name of the Directions class is based on the name of the Fragment and there can only be one instance of a particular class at a time. As per this issue with Safe Args, there is no warning when you are overwriting one Directions class from one from another graph - the last one wins. This is why reusing the same fragment in a different graph invalidates the Directions class from the first graph.

Of course, if your second graph's fragment has different actions, different arguments, or anything at all different about it, it should have a different fragment class as well - if your single fragment class were to use arguments or actions from another graph, they would fail as they would not exist in that graph.

As mentioned in that bug:

For a destination with an android:name, you'd want to include that android:name in only one place in your graph, referencing that shared destination from all of the places that need access to it (as a destination can access any sibling destinations of their parent graph).

Post a Comment for "When I Add The Same Fragment To Second Navigation Graph, Don´t Recognize The Action Class"