Navigate Directly via a Deep Link

Kotlin and Android Development featuring Jetpack — by Michael Fazio (75 / 125)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Pass Data with Safe Args | TOC | Summary and Next Steps 👉

Deep links are a way to go directly to any destination in our app, even ones not in the nav drawer. The Navigation library supports two types of deep links: explicit and implicit.

Explicit deep links are used with things like app widgets or notifications, for example. We build up the pieces of the link, complete with any arguments we need, and head over to the destination. We don’t have a good spot for an explicit deep link now, but we’ll add one in Chapter 13, Send Info to and from the Android Baseball League App.

Implicit deep links, on the other hand, are URIs (uniform resource identifiers, generally web links) that map to a destination. For example, we can have a link like https://link.mfazio.dev/teams/GB?teamName=Green%20Bay%20Skyline that will take us to the Skyline team page.

The navigation component helps us out here by allowing us to add <deepLink> tags in nav_graph.xml, then reference that nav graph in our AndroidManifest.xml file.

Add an Implicit Deep Link

Inside nav_graph.xml, add a new <deepLink> tag inside the Single Team <fragment> tag:

​ <fragment
​ android:id=​"@+id/singleTeamFragment"​
​ android:name=​"dev.mfazio.abl.teams.SingleTeamFragment"​
​…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.