# NavDeepLinkBuilder

Artifact: [androidx.navigation:navigation-runtime](https://developer.android.com/jetpack/androidx/releases/navigation) [View Source](https://cs.android.com/search?q=file:androidx/navigation/NavDeepLinkBuilder.android.kt+class:androidx.navigation.NavDeepLinkBuilder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

*** ** * ** ***

Common/AllAndroid/JVMJavaScript
- android

  ```
  class NavDeepLinkBuilder
  ```

*** ** * ** ***

Class used to construct deep links to a particular destination in a `https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph`.

When this deep link is triggered:

1. The task is cleared.

2. The destination and all of its parents will be on the back stack.

3. Calling `https://developer.android.com/reference/kotlin/androidx/navigation/NavController#navigateUp()` will navigate to the parent of the destination.

The parent of the destination is the `https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph#getStartDestination()` of the containing `https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph`. In the cases where the destination is the start destination of its containing navigation graph, the start destination of its grandparent is used.

You can construct an instance directly with `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` or build one using an existing `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` via `https://developer.android.com/reference/kotlin/androidx/navigation/NavController#createDeepLink()`.

If the context passed in here is not an `https://developer.android.com/reference/android/app/Activity.html`, this method will use `https://developer.android.com/reference/android/content/pm/PackageManager.html#getLaunchIntentForPackage(java.lang.String)` as the default activity to launch, if available.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setComponentName(java.lang.Class)` |   |

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#NavDeepLinkBuilder(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` | android |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#addDestination(kotlin.Int,android.os.Bundle)(destId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, args: https://developer.android.com/reference/android/os/Bundle.html?)` Add a new destination id to deep link to. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#addDestination(kotlin.String,android.os.Bundle)(route: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, args: https://developer.android.com/reference/android/os/Bundle.html?)` Add a new destination route to deep link to. | android |
| `https://developer.android.com/reference/android/app/PendingIntent.html` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#createPendingIntent()()` Construct a `https://developer.android.com/reference/android/app/PendingIntent.html` to the `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)`. | android |
| `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#createTaskStackBuilder()()` Construct the full `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder` needed to deep link to the given destination. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setArguments(android.os.Bundle)(args: https://developer.android.com/reference/android/os/Bundle.html?)` Set optional arguments to send onto every destination created by this deep link. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setComponentName(java.lang.Class)(activityClass: https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/android/app/Activity.html?>)` Sets an explicit Activity to be started by the deep link created by this class. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setComponentName(android.content.ComponentName)(componentName: https://developer.android.com/reference/android/content/ComponentName.html)` Sets an explicit Activity to be started by the deep link created by this class. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)(destId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, args: https://developer.android.com/reference/android/os/Bundle.html?)` Sets the destination id to deep link to. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.String,android.os.Bundle)(destRoute: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, args: https://developer.android.com/reference/android/os/Bundle.html?)` Sets the destination route to deep link to. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setGraph(kotlin.Int)(navGraphId: @https://developer.android.com/reference/kotlin/androidx/annotation/NavigationRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the graph that contains the `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)`. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setGraph(androidx.navigation.NavGraph)(navGraph: https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph)` Sets the graph that contains the `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)`. | android |

## Public constructors

### NavDeepLinkBuilder

android Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
NavDeepLinkBuilder(context: Context)
```

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | Context used to create deep links |

## Public functions

### addDestination

android Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
fun addDestination(destId: @IdRes Int, args: Bundle? = null): NavDeepLinkBuilder
```

Add a new destination id to deep link to. This builds off any previous calls to this method or calls to `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)`, building the minimal synthetic back stack of start destinations between the previous deep link destination and the newly added deep link destination.

This means that if R.navigation.nav_graph has startDestination= R.id.start_destination,

```kotlin
navDeepLinkBuilder
   .setGraph(R.navigation.nav_graph)
   .addDestination(R.id.second_destination, null)
```

is equivalent to

```kotlin
navDeepLinkBuilder
   .setGraph(R.navigation.nav_graph)
   .addDestination(R.id.start_destination, null)
   .addDestination(R.id.second_destination, null)
```

Use the second form to assign specific arguments to the start destination.

| Parameters |
|---|---|
| `destId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | destination ID to deep link to. |
| `args: https://developer.android.com/reference/android/os/Bundle.html? = null` | Arguments to pass to this destination and any synthetic back stack created due to this destination being added. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |

### addDestination

android Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
fun addDestination(route: String, args: Bundle? = null): NavDeepLinkBuilder
```

Add a new destination route to deep link to. This builds off any previous calls to this method or calls to .setDestination, building the minimal synthetic back stack of start destinations between the previous deep link destination and the newly added deep link destination.

| Parameters |
|---|---|
| `route: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | destination route to deep link to. |
| `args: https://developer.android.com/reference/android/os/Bundle.html? = null` | Arguments to pass to this destination and any synthetic back stack created due to this destination being added. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |

### createPendingIntent

android Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
fun createPendingIntent(): PendingIntent
```

Construct a `https://developer.android.com/reference/android/app/PendingIntent.html` to the `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)`.

This constructs the entire `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#createTaskStackBuilder()` needed.

You must have `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setGraph(kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)` before calling this method.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/app/PendingIntent.html` | a PendingIntent constructed with `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder#getPendingIntent(int,int)` to deep link to the given destination |

### createTaskStackBuilder

android Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
fun createTaskStackBuilder(): TaskStackBuilder
```

Construct the full `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder` needed to deep link to the given destination.

You must have `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setGraph(kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)` before calling this method.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder` | a `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder` which can be used to `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder#startActivities()` or `https://developer.android.com/reference/kotlin/androidx/core/app/TaskStackBuilder#getPendingIntent(int,int)` to deep link to the given destination. |

### setArguments

android Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
fun setArguments(args: Bundle?): NavDeepLinkBuilder
```

Set optional arguments to send onto every destination created by this deep link.

| Parameters |
|---|---|
| `args: https://developer.android.com/reference/android/os/Bundle.html?` | arguments to pass to each destination |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |

### setComponentName

android Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
fun setComponentName(activityClass: Class<Activity?>): NavDeepLinkBuilder
```

Sets an explicit Activity to be started by the deep link created by this class.

| Parameters |
|---|---|
| `activityClass: https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/android/app/Activity.html?>` | The Activity to start. This Activity should have a `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` which uses the same `https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph` used to construct this deep link. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |

### setComponentName

android Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
fun setComponentName(componentName: ComponentName): NavDeepLinkBuilder
```

Sets an explicit Activity to be started by the deep link created by this class.

| Parameters |
|---|---|
| `componentName: https://developer.android.com/reference/android/content/ComponentName.html` | The Activity to start. This Activity should have a `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` which uses the same `https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph` used to construct this deep link. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |

### setDestination

android Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
fun setDestination(destId: @IdRes Int, args: Bundle? = null): NavDeepLinkBuilder
```

Sets the destination id to deep link to. Any destinations previous added via `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#addDestination(kotlin.Int,android.os.Bundle)` are cleared, effectively resetting this object back to only this single destination.

| Parameters |
|---|---|
| `destId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | destination ID to deep link to. |
| `args: https://developer.android.com/reference/android/os/Bundle.html? = null` | Arguments to pass to this destination and any synthetic back stack created due to this destination being added. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |

### setDestination

android Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
fun setDestination(destRoute: String, args: Bundle? = null): NavDeepLinkBuilder
```

Sets the destination route to deep link to. Any destinations previous added via .addDestination are cleared, effectively resetting this object back to only this single destination.

| Parameters |
|---|---|
| `destRoute: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | destination route to deep link to. |
| `args: https://developer.android.com/reference/android/os/Bundle.html? = null` | Arguments to pass to this destination and any synthetic back stack created due to this destination being added. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |

### setGraph

android Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
fun setGraph(navGraphId: @NavigationRes Int): NavDeepLinkBuilder
```

Sets the graph that contains the `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)`.

| Parameters |
|---|---|
| `navGraphId: @https://developer.android.com/reference/kotlin/androidx/annotation/NavigationRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | ID of the `https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph` containing the deep link destination |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |

### setGraph

android Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
fun setGraph(navGraph: NavGraph): NavDeepLinkBuilder
```

Sets the graph that contains the `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder#setDestination(kotlin.Int,android.os.Bundle)`.

If you do not have access to a `https://developer.android.com/reference/kotlin/androidx/navigation/NavController`, you can create a `https://developer.android.com/reference/kotlin/androidx/navigation/NavigatorProvider` and use that to programmatically construct a navigation graph or use `https://developer.android.com/reference/kotlin/androidx/navigation/NavInflater`.

| Parameters |
|---|---|
| `navGraph: https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph` | The `https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph` containing the deep link destination |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkBuilder` | this object for chaining |