Skip to content

Android Navigation Deep Link — Complete Guide

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Android Navigation Deep Link. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

Your deep link opens the app but shows a blank screen, or the URI parameters don't get parsed, or the back stack is wrong after deep linking.

Wrong Approach ❌

<!-- Deep link without proper URI pattern -->
<deepLink app:uri="myapp://details" /> <!-- No parameters -->

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
</intent-filter>

Output: Deep link opens but with hardcoded destination — no parameter matching.

Right Approach ✅

<!-- Correct deep link with parameters -->
<deepLink app:uri="myapp://details/{itemId}" />
<deepLink app:uri="https://www.example.com/items/{itemId}" />

<!-- In Manifest -->
<activity android:name=".MainActivity"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:scheme="myapp"
            android:host="details" />
    </intent-filter>
    <nav-graph android:value="@navigation/nav_graph" />
</activity>
// Handling deep link programmatically
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // NavController handles pending deep links automatically
        // For manual handling:
        intent?.data?.let { uri ->
            findNavController(R.id.nav_host).handleDeepLink(intent)
        }
    }
}

Output: Deep link navigates to correct destination with parsed parameters.

Prevention

  • Use {paramName} placeholders in URI patterns.
  • Register <nav-graph> in the manifest to auto-handle deep links.
  • Use pendingIntent for notification deep links with NavDeepLinkBuilder.
  • Test deep links with adb shell am start -d "myapp://details/123".
  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world Android code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How do I test deep links from the command line?

Use adb shell am start -W -a Android.intent.action.VIEW -d "myapp://details/123" com.example.app. Add -W to wait for the activity to start.

### What is the difference between implicit and explicit deep links?

Explicit deep links target a specific activity. Implicit deep links use intent-filters to match URIs. Navigation Component uses implicit deep links with the <nav-graph> tag.

### How do I clear the back stack on deep link?

Use app:popUpTo="@id/rootDestination" and app:popUpToInclusive="true" on the deep link destination in the nav graph.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro