NavDestination
open class NavDestination
kotlin.Any | |
↳ | androidx.navigation.NavDestination |
NavDestination represents one node within an overall navigation graph.
Each destination is associated with a Navigator
which knows how to navigate to this particular destination.
Destinations declare a set of actions
that they support. These actions form a navigation API for the destination; the same actions declared on different destinations that fill similar roles allow application code to navigate based on semantic intent.
Each destination has a set of arguments
that will be applied when navigating
to that destination. Any default values for those arguments can be overridden at the time of navigation.
Summary
Nested classes | |
---|---|
This optional annotation allows tooling to offer auto-complete for the |
Public constructors | |
---|---|
<init>(@NonNull : Navigator<out NavDestination!>) NavDestinations should be created via |
|
NavDestinations should be created via |
Public methods | |
---|---|
Unit |
addArgument(@NonNull : String, @NonNull : NavArgument) Sets an argument type for an argument name |
Unit |
addDeepLink(@NonNull : String) Add a deep link to this destination. |
Unit |
addDeepLink(@NonNull : NavDeepLink) Add a deep link to this destination. |
NavAction? |
Returns the destination ID for a given action. |
MutableMap<String!, NavArgument!> |
Get the arguments supported by this destination. |
Int |
getId() Returns the destination's unique ID. |
CharSequence? |
getLabel() Gets the descriptive label of this destination. |
String |
Returns the name associated with this destination's |
NavGraph? |
Gets the |
open Boolean |
hasDeepLink(@NonNull : Uri) Checks the given deep link |
open Boolean |
hasDeepLink(@NonNull : NavDeepLinkRequest) Checks the given |
open Unit |
onInflate(@NonNull : Context, @NonNull : AttributeSet) Called when inflating a destination from a resource. |
Unit |
Sets a destination ID for an action ID. |
Unit |
Sets a destination ID for an action ID. |
Unit |
removeAction(@IdRes : Int) Unsets the destination ID for an action ID. |
Unit |
removeArgument(@NonNull : String) Unsets the argument type for an argument name. |
Unit |
Sets the destination's unique ID. |
Unit |
setLabel(@Nullable : CharSequence?) Sets the descriptive label of this destination. |
open String |
toString() |
Protected methods | |
---|---|
open static Class<out C> |
parseClassFromName(@NonNull : Context, @NonNull : String, @NonNull : Class<out C>) Parse the class associated with this destination from a raw name, generally extracted from the |
Public constructors
<init>
NavDestination(@NonNull : Navigator<out NavDestination!>)
NavDestinations should be created via Navigator#createDestination
.
This constructor requires that the given Navigator has a Navigator.Name
annotation.
<init>
NavDestination(@NonNull : String)
NavDestinations should be created via Navigator#createDestination
.
Public methods
addArgument
fun addArgument(
@NonNull : String,
@NonNull : NavArgument
): Unit
Sets an argument type for an argument name
Parameters | |
---|---|
argumentName |
String: argument object to associate with destination |
addDeepLink
fun addDeepLink(@NonNull : String): Unit
Add a deep link to this destination. Matching Uris sent to NavController#handleDeepLink(Intent)
or NavController#navigate(Uri)
will trigger navigating to this destination.
In addition to a direct Uri match, the following features are supported:
- Uris without a scheme are assumed as http and https. For example,
www.example.com
will matchhttp://www.example.com
andhttps://www.example.com
. - Placeholders in the form of
{placeholder_name}
matches 1 or more characters. The String value of the placeholder will be available in the argumentsBundle
with a key of the same name. For example,http://www.example.com/users/{id}
will matchhttp://www.example.com/users/4
. - The
.*
wildcard can be used to match 0 or more characters.
<deepLink app:uri="uriPattern" />
elements as a child to your destination.
Deep links added in navigation XML files will automatically replace instances of ${applicationId}
with the applicationId of your app. Programmatically added deep links should use Context#getPackageName()
directly when constructing the uriPattern.
Parameters | |
---|---|
uriPattern |
String: The uri pattern to add as a deep link |
addDeepLink
fun addDeepLink(@NonNull : NavDeepLink): Unit
Add a deep link to this destination. Uris that match the given NavDeepLink
uri sent to NavController#handleDeepLink(Intent)
or NavController#navigate(NavDeepLinkRequest)
will trigger navigating to this destination.
In addition to a direct Uri match, the following features are supported:
- Uris without a scheme are assumed as http and https. For example,
www.example.com
will matchhttp://www.example.com
andhttps://www.example.com
. - Placeholders in the form of
{placeholder_name}
matches 1 or more characters. The String value of the placeholder will be available in the argumentsBundle
with a key of the same name. For example,http://www.example.com/users/{id}
will matchhttp://www.example.com/users/4
. - The
.*
wildcard can be used to match 0 or more characters.
<deepLink app:uri="uriPattern" />
elements as a child to your destination.
Custom actions and mimetypes are also supported by NavDeepLink
and can be declared in your navigation XML files by adding <app:action="android.intent.action.SOME_ACTION" />
or <app:mimetype="type/subtype" />
as part of your deepLink declaration.
Deep link Uris, actions, and mimetypes added in navigation XML files will automatically replace instances of ${applicationId}
with the applicationId of your app. Programmatically added deep links should use Context#getPackageName()
directly when constructing the uriPattern.
When matching deep links for calls to NavController#handleDeepLink(Intent)
or NavController#navigate(NavDeepLinkRequest)
the order of precedence is as follows: the deep link with the most matching arguments will be chosen, followed by the deep link with a matching action, followed by the best matching mimeType (e.i. when matching mimeType image/jpg: image/* > *\/jpg > *\/*).
Parameters | |
---|---|
navDeepLink |
NavDeepLink: The NavDeepLink to add as a deep link |
getAction
@Nullable fun getAction(