Jetpack Navigation: Getting Started

Aug 10 2021 · Kotlin 1.4, Android 11, Android Studio 4.2.1

Part 3: Add Animations & Deep Links

12. Deep Link with Custom URI

Episode complete

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 11. Associate a Web Link with a Destination

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 12. Deep Link with Custom URI

Explore more resources on our website related to Navigation, such as our The Navigation Architecture Component Tutorial: Getting Started, Navigation Component for Android Part 2: Graphs and Deep Links and Navigation Component for Android Part 3: Transition and Navigation. Also stay tuned for more materials coming soon! :]

Transcript: 12. Deep Link with Custom URI

In production apps, Navigation graph is likely to be complex and there could be a requirement to navigate directly to some intermediate screen from one of initial screens.

You can utilize Deep link with custom URI for this purpose. It allows you to navigate to any fragment by URI.

In this episode, you will create a deep link to Welcome screen from Main screen.

Open the starter project for this episode. Go to nav_graph.xml. In the Design view, with WelcomeFragment selected, find the Deep Links section on the Attributes panel.

Click + sign, add the following in the URI textfield:

authorizeme://home/welcome

Click Add button. Go to code view, confirm deeplink added for WelcomeFragment. Here, you set WelcomeFragment as destination for this particular URI.

Now, go to MainFragment. Inside OnClickListener of fab, add the following code:

v ->
  v.findNavController().navigate(Uri.parse("authorizeme://home/welcome"))

Import android.net.Uri for Uri. Here, on the click of fab, you navigate via URI that you have just configured.

Build and run the app to see the Navigation in action!

Click on fab and you lend at Welcome screen.Congratulations! Custom URI based deep links is just a single line of code! Cool, isn’t it :]