NAVIGATE BETWEEN MODULES WITH DEEP LINK
Modularization in Android refers to dividing an Android application into smaller, self-contained modules that can be developed, tested, and…
NAVIGATE BETWEEN MODULES WITH DEEP LINK
Photo by Nik on Unsplash
Modularization in Android refers to dividing an Android application into smaller, self-contained modules that can be developed, tested, and maintained independently. Each module focuses on a specific functionality or feature of the application and encapsulates its own set of code, resources, and dependencies.
there are some benefits of modularization and disadvantages for it and I’m not want to explain them I want to talk about how we can navigate between them.
if you read about it every in Heabrid way of modularization you must make a UI module for every feature and if you want to make navigating between I think have some solutions but I gonna use Deep Link for it.
at first, you should create a sealed interface not a sealed class because of our purpose sealed interface is reasonable
If you want to read more about sealed class vs sealed interface read this paper.
sealed interface CreateDeepLink {
val module: String
val fragment: String
fun createUri(): Uri
}
Ok, it would be best if you defined the module and fragment you want to navigate to it and also a function for createUri for creating URI.
so I suppose you want to navigate to userFragment cause this is the fragment you navigate to when come from splash or the token is expired so as below create a class like this:
class LinkToUserFragment(private val data:String) : CreateDeepLink {
override val module: String
get() = "user"
override val fragment: String
get() = "userFragment"
override fun createUri(): Uri {
return "modularization://${this.module}/${this.fragment}/${this.data}".toUri()
}
}
class extended from CreateDeepLink so you override three attributes of it like module, fragment, and createUI. here you define all of them and what they should be and at the end createUI as you have decided. I also pass data to it to show how you can pass data to deep links like navigation you can see what data or type you’re passing to it. Add data to the end of URI and create uri with toUri().
now go to where you want the to navigation happens, write this code
findNavController().navigate(
LinkToUserFragment(data = "test").createUri()
)
so all navigation could happen like these you can create a class whose name is NavigationClass and write all navigation in it and use them wherever you want
In the end, be careful about creating navigation in hybrid. All UIs are modules and you have to create a navigation Resouce for them and also add fragments to it, be careful about startDestination you must define it when you created all navigation Resouces go to the app module and create a navigation Resouce for it and add all the navigation Resouces like below and create nested navigation:
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:startDestination="@id/login_navgraph">
<include app:graph="@navigation/login_navgraph" />
<include app:graph="@navigation/user_navgraph" />
</navigation> 메타데이터
- post_id
- 95fc86eb047c
- slug
- navigate-between-modules-with-deep-link-95fc86eb047c
- url
- https://medium.com/@alirezaramezani190/navigate-between-modules-with-deep-link-95fc86eb047c
- canonical_url
- https://medium.com/@alirezaramezani190/navigate-between-modules-with-deep-link-95fc86eb047c
- author_url
- https://medium.com/@alirezaramezani190
- status
- ok
- fetched_at
- 2026-08-18 18:48:57