# Scaling with Deeplinks on Android

DevFeed: [Scaling with Deeplinks on Android](<https://devfeed.tech/articles/scaling-with-deeplinks-on-android-20042.md>)

Original publisher: [Read original article](<https://technology.doximity.com/articles/scaling-with-deeplinks-on-android>)

Author: Doximity

Published: 2024-04-08T11:34:00Z

Content type: article

Language: en

Sources: [Doximity](<https://devfeed.tech/sources/doximity.md>)

Topics: [deeplinks](<https://devfeed.tech/topics/deeplinks.md>), [Android](<https://devfeed.tech/topics/android.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [deeplinks](<https://devfeed.tech/tags/deeplinks.md>), [scaling](<https://devfeed.tech/tags/scaling.md>)

## AI overview

An initial Android deeplink router handled 12 routes by injecting individual handlers into a list and trying them in order. Near 50 routes, that wiring became cumbersome, and overlapping, order-sensitive definitions could prevent a valid route from matching. The described redesign introduces an annotation and a build-time generated class to maintain the handler list, then merges definitions so each top-level path maps to only one handler. A map from top-level paths enables direct lookup and avoids relying on route ordering. The excerpt begins describing annotation-processor implementation but ends before its details.

## Source excerpt

Deeplinking support in Android is relatively straightforward. You declare your deeplinks in the app's manifest, receive the incoming Intent passed in to your Activity and then navigate the user to the associated destination. This pipeline works just fine when you only need to support a handful of deeplinks. What happens though as the number of deeplinks grow? How do you deal with several dozen, or possibly even hundreds, of deeplinks? First Stab at Deeplinks When we first implemented deeplinking in our app, we only had to support 12 different deeplinks. We introduced a DeeplinkRouter class that would take the incoming Intent and determine where to navigate the user: interface Deeplink { fun route(uri: Uri): Boolean } class NotificationsDeeplink(val navigator: Navigator) : Deeplink { override fun route(uri: Uri): Boolean { return if (uri.path == "/notifications") { navigator.goToNotifications() true } else { false } } class ProfileDeeplink( val navigator: Navigator, val userRepository: UserRepository ) : Deeplink { override fun route(uri: Uri): Boolean { val profileId = uri.getQueryParameter("id") val isCurrentUser = userRepository.getCurrentUser().id == profileId return if (uri.path == "/profile" && profileId != null) { navigator.goToProfile(profileId, showColleagues = isCurrentUser) true } else { false } } } // ... more deeplink definitions ... class DeeplinkRouter( notificationsDeeplink: NotificationsDeeplink, profileDeeplink: ProfileDeeplink, // ... ) { private val deeplinks = listOf( notificationsDeeplink, profileDeeplink, // ... ) fun route(intent: Intent) { intent.data?.let { uri -> deeplinks.find { it.route(uri) } } } } Problems at Scale As the number of deeplinks and the complexity of their definitions grew, two big issues started to emerge. The first was managing the sheer number of deeplinks - we had nearly 50 at one point! Each of these had to be injected into DeeplinkRouter and then passed to its internal deeplinks list. We decided to resolve this by int