Android — Clean Architecture With Dynamic-Features and Hilt/Dagger2 (Pt.2)

Pedro Okawa
Mar 4 · 2 min read
Bologna — Italy (2019)

Introduction

Navigation

nav_home

As you can see, by adding the dynamic navigation library we have access to the “include-dynamic” object, which requires some parameters to make it work, you may take a look at those parameters on Google’s documentation page, but a good hint for you is that you can use the “${applicationId}” to avoid mistyping the path otherwise, you must define it as:

app:graphPackage="com.okawa.blockchain.mkt.stats"
nav_pools

Inside our feature module, we must define our navigation file, and here’s one of the most important details, the id defined on our “nav_pools” must be the same created on the “nav_home”. In other words, DO NOT add the plus sign here:

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@id/nav_pools" <--- DO NOT ADD PLUS SIGN HERE
app:startDestination="@id/fragment_pools">

If you add the plus sign here you are going to declare a new id for the navigation file and it won’t match, and the result is this one:

2021-03-04 18:21:27.913 22314-22314/com.okawa.blockchain.mkt E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.okawa.blockchain.mkt, PID: 22314
java.lang.IllegalStateException: The included <navigation>'s id com.okawa.blockchain.mkt.pools:id/nav_pools is different from the destination id com.okawa.blockchain.mkt:id/nav_pools. Either remove the <navigation> id or make them match.

Now we must connect our features and in order to do so, we are going to use the bottom navigation view, first define the menu that is going to be used.

menu_bottom_home

The ids must also match here, the app will not crash if it doesn’t, but the navigation won’t take any action, as you can see in the next animation.

Non-matching ids error

Now we add the menu to our activity file and programmatically setup the bottom navigation menu using the setupWithNavController function.

activity_home
HomeActivity

Voilá!! 🎉
We now have the dynamic navigation working and for this post that’s all.
In our next article, we are going to setup Hilt and Dagger to use the dependency injection.

Any thoughts ideas or suggestions, please add some comments.

Geek Culture

Proud to geek out.

Sign up for Geek Culture Hits

By Geek Culture

Subscribe to receive top 10 most read stories of Geek Culture — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Pedro Okawa

Written by

Android Engineer @Triller

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store