NavDeepLinkBuilder

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>(@NonNull context: Context)

Construct a new NavDeepLinkBuilder.

Public methods
PendingIntent

Construct a PendingIntent to the deep link destination.

TaskStackBuilder

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

NavDeepLinkBuilder
setArguments(@Nullable args: Bundle?)

Set optional arguments to send onto the destination

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

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

NavDeepLinkBuilder
setComponentName(@NonNull componentName: ComponentName)

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

NavDeepLinkBuilder
setDestination(@IdRes destId: Int)

Sets the destination id to deep link to.

NavDeepLinkBuilder
setGraph(@NavigationRes navGraphId: Int)

Sets the graph that contains the deep link destination.

NavDeepLinkBuilder
setGraph(@NonNull navGraph: NavGraph)

Sets the graph that contains the deep link destination.

Public constructors

<init>

NavDeepLinkBuilder(@NonNull 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

See Also

    Public methods

    createPendingIntent

    @NonNull fun createPendingIntent(): PendingIntent

    Construct a PendingIntent to the deep link destination.

    This constructs the entire task stack needed.

    You must have #setGraph 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

    createTaskStackBuilder

    @NonNull fun createTaskStackBuilder(): TaskStackBuilder

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

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

    Return
    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 fun setArguments(@Nullable 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

    setComponentName

    @NonNull fun setComponentName(@NonNull 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

    @NonNull fun setComponentName(@NonNull 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

    @NonNull fun setDestination(@IdRes 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

    setGraph

    @NonNull fun setGraph(@NavigationRes 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

    @NonNull fun setGraph(@NonNull navGraph: NavGraph): NavDeepLinkBuilder

    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
    navGraph NavGraph: The NavGraph containing the deep link destination
    Return
    NavDeepLinkBuilder this object for chaining