NavDeepLinkBuilder

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.

See also
setComponentName

Summary

Public constructors

Public methods

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

Add a new destination id to deep link to.

final @NonNull NavDeepLinkBuilder

Add a new destination route to deep link to.

final @NonNull PendingIntent

Construct a PendingIntent to the deep link destination.

final @NonNull TaskStackBuilder

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

final @NonNull NavDeepLinkBuilder

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

final @NonNull NavDeepLinkBuilder

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

final @NonNull NavDeepLinkBuilder

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

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

Sets the destination id to deep link to.

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

Sets the destination route to deep link to.

final @NonNull NavDeepLinkBuilder
setGraph(@NavigationRes int navGraphId)

Sets the graph that contains the deep link destination.

final @NonNull NavDeepLinkBuilder

Sets the graph that contains the deep link destination.

Public constructors

@NonNull
public final NavDeepLinkBuilder(@NonNull Context context)
Parameters
@NonNull Context context

Context used to create deep links

Public methods

addDestination

@NonNull
public final NavDeepLinkBuilder addDestination(@IdRes int destId, @Nullable 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.

Parameters
@IdRes int destId

destination ID to deep link to.

@Nullable Bundle args

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

Returns
NavDeepLinkBuilder

this object for chaining

addDestination

@NonNull
public final NavDeepLinkBuilder addDestination(@NonNull String route, @Nullable 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.

@Nullable Bundle args

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

Returns
NavDeepLinkBuilder

this object for chaining

createPendingIntent

@NonNull
public final 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 to deep link to the given destination

createTaskStackBuilder

@NonNull
public final 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

@NonNull
public final NavDeepLinkBuilder setArguments(@Nullable Bundle args)

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

Parameters
@Nullable Bundle args

arguments to pass to each destination

Returns
NavDeepLinkBuilder

this object for chaining

setComponentName

@NonNull
public final NavDeepLinkBuilder setComponentName(@NonNull Class<@NonNull Activity> activityClass)

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

Parameters
@NonNull Class<@NonNull Activity> activityClass

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

@NonNull
public final NavDeepLinkBuilder setComponentName(@NonNull ComponentName componentName)

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

Parameters
@NonNull 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

@NonNull
public final NavDeepLinkBuilder setDestination(@IdRes int destId, @Nullable 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.

@Nullable Bundle args

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

Returns
NavDeepLinkBuilder

this object for chaining

setDestination

@NonNull
public final NavDeepLinkBuilder setDestination(@NonNull String destRoute, @Nullable 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.

@Nullable Bundle args

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

Returns
NavDeepLinkBuilder

this object for chaining

setGraph

@NonNull
public final NavDeepLinkBuilder setGraph(@NavigationRes int navGraphId)

Sets the graph that contains the deep link destination.

Parameters
@NavigationRes int navGraphId

ID of the NavGraph containing the deep link destination

Returns
NavDeepLinkBuilder

this object for chaining

setGraph

@NonNull
public final NavDeepLinkBuilder setGraph(@NonNull NavGraph navGraph)

Sets the graph that contains the deep link destination.

If you do not have access to a NavController, you can create a NavigatorProvider and use that to programmatically construct a navigation graph or use NavInflater.

Parameters
@NonNull NavGraph navGraph

The NavGraph containing the deep link destination

Returns
NavDeepLinkBuilder

this object for chaining