Search code examples
androidandroid-intentandroid-architecture-componentsandroid-instant-appsandroid-architecture-navigation

Navigation component with instant/(dynamic-)feature modules


I'm trying to implement the new navigation component with dynamic features

So the structure looks like this:

  • app (has dynamic dynamicFeatures = [] included in gradle)
  • features

    • login
    • home
    • etc.
  • library -> globalNav

I've been reading a lot with no success how to glue these together without depending on each other as each feature is completely isolated

e.g The app (app module) starts with the SplashActivity and checks the session state, so my question is how should I start the login_graph or home_graph and in the first case, start the home after finishing the auth flow?

The way I'm currently trying gluing'em together is using a globalNav module (android-library) I found a couple of workarounds:

  • Complete classpath, meaning I start the intent with the className (bad as this is not really scalable and makes maintaining a PITA)
Intent().setClassName(context.packageName, className).also { context.startActivity(it) }
  • Deeplinks (the one I wanted to use as my nav graph already has those) but for some reason, it always shows the "Choose complete action" picker even though only my app takes it.

    • I've already tried using actions but the same behavior as deeplinks

Any suggestions would be great :)


PS: Some references that I've been viewing/reading on:

PSS: I'm actively trying to figure this out if I find a good solution I'll make sure to answer too.

EDIT

For anyone interested in this, as it isn't currently supported, you can star the issue here: https://issuetracker.google.com/issues/132170186


Solution

  • Navigation in on-demand feature modules is supported by using the navigation-dynamic-feature-* components. The most recent version can be found on maven.google.com.

    We do have a sample available that demonstrates both XML and Kotlin DSL declaration possibilites.

    The documentation is available here

    For more info you can also watch the recording on this from the Android Dev Summit 2019.