ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Follow publication

An Effective Deep Link & Navigation Approach For Multi Modular Android Applications

If you didn’t read my last articles which were I wrote them to reach this article, you might want to read them to understand why I wrote this article.

Part One:

Part Two:

If you were read them already, here we are to tell end of this story!

I know, it’s been a long story already 😢

Part Three

You must already know what is problem and what are we trying to achieve. Shortly we are trying to modularize our application, manage navigations between activities which is in the separate modules. Also while we implement navigations we want to have control over deep linking which provides navigations from external sources.

I’ve already implemented this in one of my application which is a small dating application and using it. By modularizing the application I’ve experienced lots of things but I’ll explain this by another story.

Let’s see what we have done!

Modules

I’ve modularized app and here is the modules:

Modules

Each of our modules has their own business. I’ll explain this architecture on the next article.

common: In this module we have our common resources and classes which developed & added only for this application. We have all of our drawable, string, dimensions, raw resources also in this module. Also we store our router data classes in here. These router data classes used by the routables which is responsible about the navigation between activities.

What is Routable Class?

These classes has the responsibility of navigation. We declare our navigation informations from these classes and use them while we navigate to the activity.

Here is our Router interface:

And here is the example usage:

If you want to implement another logic for deep linking you can override it from here or you can handle data from MainActivity as bundle. But it’s better to handle data from routable.

What is Router Class?

Router class is the classes are container of the information about the navigating activity. For example if you want to pass some value to routing activity you should add those values to Router class. These values passes via routable classes. Routable classes are the container of the router information i.e. navigating activity, navigation code & navigation data.

Base RouterData class is only implements Parcelable, if you need more you can add it to your RouterData class. Here is the example RouterData:

We are collecting these router datas in our common module. Because we need all those routers in our all of modules for navigation from anywhere.

We have created all classes to be navigating another activity but what about navigating? We are using Router for this.

Router

Router class is the class which is the provides the navigation between activities.

Here is the router:

We need an array which contains those routables. We provide it by dependency injection by Hilt (or Dagger). You need to inject router in to your base activity.

How do we use it when we want to navigate?

router.routeToActivity(
this@SplashActivity,
MainRouterData.ROUTER_ID,
MainRouterData(userId)
)

Congrats! You’ve successfully implemented router to your application.

How should you store your classes in the project?

Here is my usage:

app: RouterModule.kt

framework: Router.kt, Routable.kt, RouterData.kt

common: MainRouterData.kt, BoardingRouterData.kt & etc.

feature_main: MainRouter.kt

feature_prelogin: BoardingRouter.kt, LoginRouter.kt & etc.

Dependecy between modules:

feature_* depends on common & framework

common depends on nothing

app depends on framework, common & each feature module.

I hope you don’t have any questions on your mind. If you have anything you can comment here. Also you can book a time with me from Superpeer.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Ali Yüce

Android & ROS (Robot Operating System) Developer

Responses (2)

Write a response