9

I have a complex navigation structure, I go from one nav graph then based on some logic, decide which nav graph to go to there. However both the nav graphs share 3 other nav graphs. See image below

Example

Currently I get a circular reference error if I try to include each nav graph in the A & B. I have also tried creating a global action, which leads to illegal argument exception since it doesn't exist on the nav graph.

Please help!!!

Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
babybadger
  • 101
  • 3
  • 3
    Did you figure it out? I have a very similar problem and I don't even understand this, as this is not circular, it's just included in multiple places which should be fine in my opinion. – A1m Sep 23 '20 at 22:31

1 Answers1

0

I also don't know how to solve this. The Navigation Component should allow the reuse of modular graphs by passing some sort of ID from the initiating graph.

The only workaround I could think of was to create a copy of the graphs that have different origins.

For example, "Graph1" would now have two versions, "Graph1_from_GraphA" and "Graph1_from_GraphB". So "GraphA" and "GraphB" would reference them respectively.

If the graphs are not that far way, there is also the solution of conditional navigation, as described in the official documentation (https://developer.android.com/guide/navigation/navigation-conditional), in which we can pop the BackStack in the NavController with a result in the SavedStateHandle and then in the previous fragment we can redirect to the desired destination.

Rui
  • 936
  • 10
  • 21