I’ve been playing around with JetPack’s Navigation Component. For the most part it’s pretty decent, although I’ve run into a few problems/cases for which I’ve not yet found a decent solution.
Let’s say we have a Single Activity app with Modular Architecture (packaging strategy?), and we don’t want to have a God module for navigation. We want all our modules to have their own nav_graph
and we want to be able to jump back and forth from graph to graph.
Let’s say we have a dependency like this:
app
--dependsOn--> library
--dependsOn--> details
. Both of library
and details
have their own nav_graphs
which know about how to navigate in each of those modules.
Now if we’re in the app
module, we would be able to directly navigate to any one of details
’ destinations, since app
knows about both library
and details
. But how do we navigate from details
to, for instance, another one of library
’s destinations?
One of the solutions I’ve found is via a Router
of some sorts (usually an Interface
inside a God
module), which is not ideal, especially if you’re using something like SafeArgs
because if you want to, for example, change a parameter you’re passing, you’d need to change the router’s method signatures etc.
The other solution I’ve found is to add destinations dynamically. I’ve not actually been able to make this work for my case, although I remember reading somewhere that if you know the fully qualified name of the class/destination you should be able to navigate to it, despite Android Studio’s warnings.
Third thing I tried was using popUpTo
with inclusive=true
in the nav_graph
definitions to kind of pop out of this graph, but I’ve had no luck with that (I was using a NavDrawer
and wanted to pop back up to a top level location).
Has anyone found a good solution to this?