NavDeepLinkBuilder

open class NavDeepLinkBuilder
kotlin.Any
   ↳ 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
<init>(context: Context)

Construct a new NavDeepLinkBuilder.

Public methods
open NavDeepLinkBuilder
setGraph(navGraphId: Int)

Sets the graph that contains the deep link destination.

open NavDeepLinkBuilder
setGraph(navGraph: NavGraph)

Sets the graph that contains the deep link destination.

open NavDeepLinkBuilder
setComponentName(activityClass: Class<out Activity!>)

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

open NavDeepLinkBuilder

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

open NavDeepLinkBuilder

Sets the destination id to deep link to.

open TaskStackBuilder

Construct the full TaskStackBuilder needed to deep link to the given destination.

open NavDeepLinkBuilder

Set optional arguments to send onto the destination

open PendingIntent

Construct a PendingIntent to the deep link destination.

Public constructors

<init>

NavDeepLinkBuilder(context: Context)

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

Parameters
context Context: Context used to create deep links

Public methods

setGraph

open fun setGraph(navGraphId: Int): NavDeepLinkBuilder

Sets the graph that contains the deep link destination.

Parameters
navGraphId Int: ID of the NavGraph containing the deep link destination
Return
NavDeepLinkBuilder: this object for chaining

setGraph

open fun setGraph(navGraph: NavGraph): NavDeepLinkBuilder

Sets the graph that contains the deep link destination.

Parameters
navGraph NavGraph: The NavGraph containing the deep link destination
Return
NavDeepLinkBuilder: this object for chaining

setComponentName

open fun setComponentName(activityClass: Class<out Activity!>): NavDeepLinkBuilder

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

Parameters
activityClass Class<out Activity!>: The Activity to start. This Activity should have a NavController which uses the same NavGraph used to construct this deep link.
Return
NavDeepLinkBuilder: this object for chaining

setComponentName

open fun setComponentName(componentName: ComponentName): NavDeepLinkBuilder

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.
Return
NavDeepLinkBuilder: this object for chaining

setDestination

open fun setDestination(destId: Int): NavDeepLinkBuilder

Sets the destination id to deep link to.

Parameters
destId Int: destination ID to deep link to.
Return
NavDeepLinkBuilder: this object for chaining

createTaskStackBuilder

open fun createTaskStackBuilder(): TaskStackBuilder

Construct the full TaskStackBuilder needed to deep link to the given destination.

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

Return
TaskStackBuilder: a TaskStackBuilder which can be used to TaskStackBuilder#startActivities() or TaskStackBuilder#getPendingIntent(int, int) to deep link to the given destination.

setArguments

open fun setArguments(args: Bundle?): NavDeepLinkBuilder

Set optional arguments to send onto the destination

Parameters
args Bundle?: arguments to pass to the destination
Return
NavDeepLinkBuilder: this object for chaining

createPendingIntent

open fun createPendingIntent(): PendingIntent

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.

Return
PendingIntent: a PendingIntent constructed with TaskStackBuilder#getPendingIntent(int, int) to deep link to the given destination