public final class NavDeepLinkBuilder

Class used to construct deep links to a particular destination in a 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 NavController.navigateUp will navigate to the parent of the destination.

The parent of the destination is the start destination of the containing navigation graph. 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 NavDeepLinkBuilder or build one using an existing NavController via NavController.createDeepLink.

If the context passed in here is not an Activity, this method will use android.content.pm.PackageManager.getLaunchIntentForPackage as the default activity to launch, if available.

Summary

Public constructors

Public methods

addDestination

public final @NonNull NavDeepLinkBuilder addDestination(@IdRes int destId, Bundle args)

Add a new destination id 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.

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

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

is equivalent to

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
@IdRes int destId

destination ID to deep link to.

Bundle args

Arguments to pass to this destination and any synthetic back stack created due to this destination being added.

addDestination

public final @NonNull NavDeepLinkBuilder addDestination(@NonNull String route, Bundle args)

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
@NonNull String route

destination route to deep link to.

Bundle args

Arguments to pass to this destination and any synthetic back stack created due to this destination being added.

setDestination

public final @NonNull NavDeepLinkBuilder setDestination(@IdRes int destId, Bundle args)

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

Parameters
@IdRes int destId

destination ID to deep link to.

Bundle args

Arguments to pass to this destination and any synthetic back stack created due to this destination being added.

setDestination

public final @NonNull NavDeepLinkBuilder setDestination(@NonNull String destRoute, Bundle args)

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
@NonNull String destRoute

destination route to deep link to.

Bundle args

Arguments to pass to this destination and any synthetic back stack created due to this destination being added.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025-05-15 UTC.