NavDeepLinkBuilder
-
android
class NavDeepLinkBuilder
Class used to construct deep links to a particular destination in a NavGraph.
When this deep link is triggered:
-
The task is cleared.
-
The destination and all of its parents will be on the back stack.
-
Calling
NavController.navigateUpwill 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 |
|
|---|---|
NavDeepLinkBuilder(context: Context) |
android
|
Public functions |
||
|---|---|---|
NavDeepLinkBuilder |
addDestination(destId: @IdRes Int, args: Bundle?)Add a new destination id to deep link to. |
android
|
NavDeepLinkBuilder |
addDestination(route: String, args: Bundle?)Add a new destination route to deep link to. |
android
|
PendingIntent |
Construct a |
android
|
TaskStackBuilder |
Construct the full |
android
|
NavDeepLinkBuilder |
setArguments(args: Bundle?)Set optional arguments to send onto every destination created by this deep link. |
android
|
NavDeepLinkBuilder |
setComponentName(activityClass: Class<Activity?>)Sets an explicit Activity to be started by the deep link created by this class. |
android
|
NavDeepLinkBuilder |
setComponentName(componentName: ComponentName)Sets an explicit Activity to be started by the deep link created by this class. |
android
|
NavDeepLinkBuilder |
setDestination(destId: @IdRes Int, args: Bundle?)Sets the destination id to deep link to. |
android
|
NavDeepLinkBuilder |
setDestination(destRoute: String, args: Bundle?)Sets the destination route to deep link to. |
android
|
NavDeepLinkBuilder |
setGraph(navGraphId: @NavigationRes Int)Sets the graph that contains the |
android
|
NavDeepLinkBuilder |
Sets the graph that contains the |
android
|
Public constructors
NavDeepLinkBuilder
NavDeepLinkBuilder(context: Context)
| Parameters | |
|---|---|
context: Context |
Context used to create deep links |
Public functions
addDestination
fun addDestination(destId: @IdRes Int, args: Bundle? = null): NavDeepLinkBuilder
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 | |
|---|---|
destId: @IdRes Int |
destination ID to deep link to. |
args: Bundle? = null |
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
fun addDestination(route: String, args: Bundle? = null): NavDeepLinkBuilder
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 | |
|---|---|
route: String |
destination route to deep link to. |
args: Bundle? = null |
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
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.
| Returns | |
|---|---|
PendingIntent |
a PendingIntent constructed with |
createTaskStackBuilder
fun createTaskStackBuilder(): TaskStackBuilder
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 |
setArguments
fun setArguments(args: Bundle?): NavDeepLinkBuilder
Set optional arguments to send onto every destination created by this deep link.
| Parameters | |
|---|---|
args: Bundle? |
arguments to pass to each destination |
| Returns | |
|---|---|
NavDeepLinkBuilder |
this object for chaining |
setComponentName
fun setComponentName(activityClass: Class<Activity?>): NavDeepLinkBuilder
Sets an explicit Activity to be started by the deep link created by this class.
| Parameters | |
|---|---|
activityClass: Class<Activity?> |
The Activity to start. This Activity should have a |
| Returns | |
|---|---|
NavDeepLinkBuilder |
this object for chaining |
setComponentName
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 |
| Returns | |
|---|---|
NavDeepLinkBuilder |
this object for chaining |
setDestination
fun setDestination(destId: @IdRes Int, args: Bundle? = null): NavDeepLinkBuilder
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 | |
|---|---|
destId: @IdRes Int |
destination ID to deep link to. |
args: Bundle? = null |
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
fun setDestination(destRoute: String, args: Bundle? = null): NavDeepLinkBuilder
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 | |
|---|---|
destRoute: String |
destination route to deep link to. |
args: Bundle? = null |
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
fun setGraph(navGraphId: @NavigationRes Int): NavDeepLinkBuilder
Sets the graph that contains the deep link destination.
| Parameters | |
|---|---|
navGraphId: @NavigationRes Int |
ID of the |
| Returns | |
|---|---|
NavDeepLinkBuilder |
this object for chaining |
setGraph
fun setGraph(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.
| Returns | |
|---|---|
NavDeepLinkBuilder |
this object for chaining |