Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

NavDeepLinkBuilder

public class NavDeepLinkBuilder
extends Object

java.lang.Object
   ↳ androidx.navigation.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(Context) or build one using an existing NavController via NavController.createDeepLink().

Summary

Public constructors

NavDeepLinkBuilder(Context context)

Construct a new NavDeepLinkBuilder.

Public methods

PendingIntent createPendingIntent()

Construct a PendingIntent to the deep link destination.

TaskStackBuilder createTaskStackBuilder()

Construct the full task stack needed to deep link to the given destination.

NavDeepLinkBuilder setArguments(Bundle args)

Set optional arguments to send onto the destination

NavDeepLinkBuilder setComponentName(Class<? extends Activity> activityClass)

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

NavDeepLinkBuilder setComponentName(ComponentName componentName)

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

NavDeepLinkBuilder setDestination(int destId)

Sets the destination id to deep link to.

NavDeepLinkBuilder setGraph(int navGraphId)

Sets the graph that contains the deep link destination.

NavDeepLinkBuilder setGraph(NavGraph navGraph)

Sets the graph that contains the deep link destination.

Inherited methods

Public constructors

public NavDeepLinkBuilder (Context context)

Construct a new NavDeepLinkBuilder. If the context passed in here is not an Activity, this method will use PackageManager.getLaunchIntentForPackage(String) as the default activity to launch, if available.

Parameters
context Context: Context used to create deep links

Public methods

createPendingIntent

public PendingIntent createPendingIntent ()

Construct a PendingIntent to the deep link destination.

This constructs the entire task stack needed.

You must have set a NavGraph and set a destination before calling this method.

Returns
PendingIntent a PendingIntent constructed with TaskStackBuilder.getPendingIntent(int, int) to deep link to the given destination

createTaskStackBuilder

public TaskStackBuilder createTaskStackBuilder ()

Construct the full task stack needed to deep link to the given destination.

You must have set a NavGraph and set a destination before calling this method.

Returns
TaskStackBuilder a TaskStackBuilder which can be used to send the deep link or create a PendingIntent to deep link to the given destination.

setArguments

public NavDeepLinkBuilder setArguments (Bundle args)

Set optional arguments to send onto the destination

Parameters
args Bundle: arguments to pass to the destination

Returns
NavDeepLinkBuilder this object for chaining

setComponentName

public NavDeepLinkBuilder setComponentName (Class<? extends Activity> activityClass)

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

Parameters
activityClass Class: The Activity to start. This Activity should have a NavController which uses the same NavGraph used to construct this deep link.

Returns
NavDeepLinkBuilder this object for chaining

setComponentName

public NavDeepLinkBuilder setComponentName (ComponentName componentName)

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

Parameters
componentName ComponentName: The Activity to start. This Activity should have a NavController which uses the same NavGraph used to construct this deep link.

Returns
NavDeepLinkBuilder this object for chaining

setDestination

public NavDeepLinkBuilder setDestination (int destId)

Sets the destination id to deep link to.

Parameters
destId int: destination ID to deep link to.

Returns
NavDeepLinkBuilder this object for chaining

setGraph

public NavDeepLinkBuilder setGraph (int navGraphId)

Sets the graph that contains the deep link destination.

Parameters
navGraphId int: ID of the NavGraph containing the deep link destination

Returns
NavDeepLinkBuilder this object for chaining

setGraph

public NavDeepLinkBuilder setGraph (NavGraph navGraph)

Sets the graph that contains the deep link destination.

Parameters
navGraph NavGraph: The NavGraph containing the deep link destination

Returns
NavDeepLinkBuilder this object for chaining