androidx.navigation

Interfaces

FloatingWindow

A marker interface for NavDestination subclasses that float above the view of other destinations (i.e. androidx.navigation.fragment.DialogFragmentNavigator.Destination).

NavArgs

An interface marking generated Args classes.

NavController.OnDestinationChangedListener

OnDestinationChangedListener receives a callback when the currentDestination or its arguments change.

NavDirections

An interface that describes a navigation operation: action's id and arguments

NavHost

A host is a single context or container for navigation via a NavController.

Navigator.Extras

Interface indicating that this class should be passed to its respective Navigator to enable Navigator specific behavior.

Classes

ActionOnlyNavDirections

An implementation of NavDirections without any arguments.

ActivityNavigator

ActivityNavigator implements cross-activity navigation.

ActivityNavigator.Destination

NavDestination for activity navigation

ActivityNavigator.Extras

Extras that can be passed to ActivityNavigator to customize what ActivityOptionsCompat and flags are passed through to the call to ActivityCompat.startActivity.

ActivityNavigator.Extras.Builder

Builder for constructing new Extras instances.

ActivityNavigatorDestinationBuilder

DSL for constructing a new ActivityNavigator.Destination

AnimBuilder

DSL for setting custom Animation or Animator resources on a NavOptionsBuilder

NamedNavArgument

Construct a named NavArgument by using the navArgument method.

NavAction

Navigation actions provide a level of indirection between your navigation code and the underlying destinations.

NavActionBuilder

DSL for building a NavAction.

NavArgsLazy

An implementation of Lazy used by android.app.Activity.navArgs and androidx.fragment.app.Fragment.navArgs.

NavArgument

NavArgument denotes an argument that is supported by a NavDestination.

NavArgument.Builder

A builder for constructing NavArgument instances.

NavArgumentBuilder

DSL for constructing a new NavArgument

NavBackStackEntry

Representation of an entry in the back stack of a androidx.navigation.NavController.

NavController

NavController manages app navigation within a NavHost.

NavDeepLink

NavDeepLink encapsulates the parsing and matching of a navigation deep link.

NavDeepLink.Builder

A builder for constructing NavDeepLink instances.

NavDeepLinkBuilder

Class used to construct deep links to a particular destination in a NavGraph.

NavDeepLinkDslBuilder

DSL for constructing a new NavDeepLink

NavDeepLinkRequest

A request for a deep link in a NavDestination.

NavDeepLinkRequest.Builder

A builder for constructing NavDeepLinkRequest instances.

NavDestination

NavDestination represents one node within an overall navigation graph.

NavDestinationBuilder

DSL for constructing a new NavDestination

NavGraph

NavGraph is a collection of NavDestination nodes fetchable by ID.

NavGraphBuilder

DSL for constructing a new NavGraph

NavGraphNavigator

A Navigator built specifically for NavGraph elements.

NavHostController

Subclass of NavController that offers additional APIs for use by a NavHost to connect the NavController to external dependencies.

NavInflater

Class which translates a navigation XML file into a NavGraph

NavOptions

NavOptions stores special options for navigate actions

NavOptions.Builder

Builder for constructing new instances of NavOptions.

NavOptionsBuilder

DSL for constructing a new NavOptions

NavType

NavType denotes the type that can be used in a NavArgument.

NavType.EnumType

EnumType is used for NavArguments holding enum values.

NavType.ParcelableArrayType

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.

NavType.ParcelableType

ParcelableType is used for passing Parcelables in NavArguments.

NavType.SerializableArrayType

SerializableArrayType is used for NavArguments that hold arrays of Serializables.

NavType.SerializableType

SerializableType is used for Serializable NavArguments.

Navigator

Navigator defines a mechanism for navigating within an app.

NavigatorProvider

A NavigationProvider stores a set of Navigators that are valid ways to navigate to a destination.

NavigatorState

The NavigatorState encapsulates the state shared between the Navigator and the NavController.

PopUpToBuilder

DSL for customizing NavOptionsBuilder.popUpTo operations.

Objects

Navigation

Entry point for navigation operations.

Annotations

NavDeepLinkDsl
NavDeepLinkSaveStateControl
NavDestination.ClassType

This optional annotation allows tooling to offer auto-complete for the android:name attribute.

NavDestinationDsl
NavOptionsDsl
Navigator.Name

This annotation should be added to each Navigator subclass to denote the default name used to register the Navigator with a NavigatorProvider.

Top-level functions summary

ActivityNavigator.Extras
ActivityNavigatorExtras(
    activityOptions: ActivityOptionsCompat?,
    flags: Int
)

Create a new ActivityNavigator.Extras instance with a specific ActivityOptionsCompat instance and/or any Intent.FLAG_ACTIVITY_ flags.

NamedNavArgument
navArgument(name: String, builder: NavArgumentBuilder.() -> Unit)

Construct a new NavArgument

NavDeepLink
navDeepLink(deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit)

Construct a new NavDeepLink

NavOptions
navOptions(optionsBuilder: NavOptionsBuilder.() -> Unit)

Construct a new NavOptions

Extension functions summary

inline Unit

This function is deprecated. Use routes to build your ActivityDestination instead

inline Unit

Construct a new ActivityNavigator.Destination

operator Boolean

Returns true if a destination with id is found in this navigation graph.

operator Boolean

Returns true if a destination with route is found in this navigation graph.

inline NavGraph
NavController.createGraph(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
)

This function is deprecated. Use routes to create your NavGraph instead

inline NavGraph
NavHost.createGraph(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
)

This function is deprecated. Use routes to create your NavGraph instead

inline NavGraph
NavController.createGraph(
    startDestination: String,
    route: String?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

inline NavGraph
NavHost.createGraph(
    startDestination: String,
    route: String?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

NavController

Find a NavController associated with a View.

NavController

Find a NavController given the id of a View and its containing Activity.

inline operator T

Retrieves a registered Navigator using the name provided by the Navigator.Name annotation.

inline operator NavDestination

Returns the destination with id.

inline operator T

Retrieves a registered Navigator by name.

inline operator NavDestination

Returns the destination with route.

inline operator Unit

Removes node from this navigation graph.

inline NavArgsLazy<Args>

Returns a Lazy delegate to access the Activity's extras as an Args instance.

inline Lazy<VM>
@MainThread
<VM : ViewModel> Fragment.navGraphViewModels(
    navGraphId: @IdRes Int,
    noinline extrasProducer: (() -> CreationExtras)?,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)?
)

Returns a property delegate to access a ViewModel scoped to a navigation graph present on the NavController back stack:

inline Lazy<VM>
@MainThread
<VM : ViewModel> Fragment.navGraphViewModels(
    navGraphRoute: String,
    noinline extrasProducer: (() -> CreationExtras)?,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)?
)

Returns a property delegate to access a ViewModel scoped to a navigation graph present on the NavController back stack:

inline NavGraph
NavigatorProvider.navigation(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
)

This function is deprecated. Use routes to build your NavGraph instead

inline Unit
NavGraphBuilder.navigation(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
)

This function is deprecated. Use routes to build your nested NavGraph instead

inline NavGraph
NavigatorProvider.navigation(
    startDestination: String,
    route: String?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

inline Unit
NavGraphBuilder.navigation(
    startDestination: String,
    route: String,
    builder: NavGraphBuilder.() -> Unit
)

Construct a nested NavGraph

inline operator Unit

Register a navigator using the name provided by the Navigator.Name annotation.

inline operator Unit

Adds a destination to this NavGraph.

inline operator Unit

Add all destinations from another collection to this one.

inline operator Navigator<NavDestination>?
NavigatorProvider.set(
    name: String,
    navigator: Navigator<NavDestination>
)

Register a Navigator by name.

Top-level functions

ActivityNavigatorExtras

fun ActivityNavigatorExtras(
    activityOptions: ActivityOptionsCompat? = null,
    flags: Int = 0
): ActivityNavigator.Extras

Create a new ActivityNavigator.Extras instance with a specific ActivityOptionsCompat instance and/or any Intent.FLAG_ACTIVITY_ flags.

Parameters
activityOptions: ActivityOptionsCompat? = null

Optional ActivityOptionsCompat to pass through to androidx.core.app.ActivityCompat.startActivity.

flags: Int = 0

Intent.FLAG_ACTIVITY_ flags to add to the Intent.

fun navArgument(name: String, builder: NavArgumentBuilder.() -> Unit): NamedNavArgument

Construct a new NavArgument

fun navDeepLink(deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit): NavDeepLink

Construct a new NavDeepLink

fun navOptions(optionsBuilder: NavOptionsBuilder.() -> Unit): NavOptions

Construct a new NavOptions

Extension functions

inline fun NavGraphBuilder.activity(id: @IdRes Int, builder: ActivityNavigatorDestinationBuilder.() -> Unit): Unit

Construct a new ActivityNavigator.Destination

operator fun NavGraph.contains(id: @IdRes Int): Boolean

Returns true if a destination with id is found in this navigation graph.

operator fun NavGraph.contains(route: String): Boolean

Returns true if a destination with route is found in this navigation graph.

inline fun NavController.createGraph(
    id: @IdRes Int = 0,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
id: @IdRes Int = 0

the graph's unique id

startDestination: @IdRes Int

the route for the start destination

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

inline fun NavHost.createGraph(
    id: @IdRes Int = 0,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

inline fun NavController.createGraph(
    startDestination: String,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: String

the route for the start destination

route: String? = null

the route for the graph

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

inline fun NavHost.createGraph(
    startDestination: String,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

findNavController

fun View.findNavController(): NavController

Find a NavController associated with a View.

Calling this on a View not within a NavHost will result in an IllegalStateException

findNavController

fun Activity.findNavController(viewId: @IdRes Int): NavController

Find a NavController given the id of a View and its containing Activity.

Calling this on a View that is not a NavHost or within a NavHost will result in an IllegalStateException

inline operator fun <T : Navigator<NavDestination>> NavigatorProvider.get(clazz: KClass<T>): T

Retrieves a registered Navigator using the name provided by the Navigator.Name annotation.

Throws
kotlin.IllegalStateException

if the Navigator has not been added

inline operator fun NavGraph.get(id: @IdRes Int): NavDestination

Returns the destination with id.

Throws
kotlin.IllegalArgumentException

if no destination is found with that id.

inline operator fun <T : Navigator<NavDestination>> NavigatorProvider.get(name: String): T

Retrieves a registered Navigator by name.

Throws
kotlin.IllegalStateException

if the Navigator has not been added

inline operator fun NavGraph.get(route: String): NavDestination

Returns the destination with route.

Throws
kotlin.IllegalArgumentException

if no destination is found with that route.

inline operator fun NavGraph.minusAssign(node: NavDestination): Unit

Removes node from this navigation graph.

@MainThread
inline fun <Args : NavArgs> Activity.navArgs(): NavArgsLazy<Args>

Returns a Lazy delegate to access the Activity's extras as an Args instance.

It is strongly recommended that this method only be used when the Activity is started by androidx.navigation.NavController.navigate with the corresponding androidx.navigation.NavDirections object, which ensures that the required arguments are present.

class MyActivity : Activity() {
val args: MyActivityArgs by navArgs()
}

This property can be accessed only after the Activity is attached to the Application, and access prior to that will result in IllegalStateException.

@MainThread
inline fun <VM : ViewModel> Fragment.navGraphViewModels(
    navGraphId: @IdRes Int,
    noinline extrasProducer: (() -> CreationExtras)? = null,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
): Lazy<VM>

Returns a property delegate to access a ViewModel scoped to a navigation graph present on the NavController back stack:

class MyFragment : Fragment() {
val viewmodel: MainViewModel by navGraphViewModels(R.id.main)
}

Custom ViewModelProvider.Factory can be defined via factoryProducer parameter, factory returned by it will be used to create ViewModel:

class MyFragment : Fragment() {
val viewmodel: MainViewModel by navGraphViewModels(R.id.main) { myFactory }
}

This property can be accessed only after this NavGraph is on the NavController back stack, and an attempt access prior to that will result in an IllegalArgumentException.

Parameters
navGraphId: @IdRes Int

ID of a NavGraph that exists on the NavController back stack

noinline extrasProducer: (() -> CreationExtras)? = null

lambda that will be called during initialization to return CreationExtras. If none is provided, this will use the extras from the NavBackStackEntry referenced by the navGraphId.

noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null

lambda that will be called during initialization to return ViewModelProvider.Factory. If none is provided, this will use the factory from the NavBackStackEntry referenced by the navGraphId.

@MainThread
inline fun <VM : ViewModel> Fragment.navGraphViewModels(
    navGraphRoute: String,
    noinline extrasProducer: (() -> CreationExtras)? = null,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
): Lazy<VM>

Returns a property delegate to access a ViewModel scoped to a navigation graph present on the NavController back stack:

class MyFragment : Fragment() {
val viewModel: MainViewModel by navGraphViewModels("main")
}

Custom ViewModelProvider.Factory can be defined via factoryProducer parameter, factory returned by it will be used to create ViewModel:

class MyFragment : Fragment() {
val viewModel: MainViewModel by navGraphViewModels("main") { myFactory }
}

This property can be accessed only after this NavGraph is on the NavController back stack, and an attempt access prior to that will result in an IllegalArgumentException.

Parameters
navGraphRoute: String

NavDestination.route of a NavGraph that exists on the NavController back stack. If a NavDestination with the given route does not exist on the back stack, an IllegalArgumentException will be thrown.

noinline extrasProducer: (() -> CreationExtras)? = null

lambda that will be called during initialization to return CreationExtras. If none is provided, this will use the extras from the NavBackStackEntry referenced by the navGraphRoute.

noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null

lambda that will be called during initialization to return ViewModelProvider.Factory. If none is provided, this will use the factory from the NavBackStackEntry referenced by the navGraphRoute.

inline fun NavigatorProvider.navigation(
    id: @IdRes Int = 0,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
id: @IdRes Int = 0

the destination's unique id

startDestination: @IdRes Int

the starting destination for this NavGraph

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
NavGraph

the newly constructed NavGraph

inline fun NavGraphBuilder.navigation(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

Parameters
id: @IdRes Int

the destination's unique id

startDestination: @IdRes Int

the starting destination for this NavGraph

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph

inline fun NavigatorProvider.navigation(
    startDestination: String,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: String

the starting destination's route for this NavGraph

route: String? = null

the destination's unique route

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
NavGraph

the newly constructed NavGraph

inline fun NavGraphBuilder.navigation(
    startDestination: String,
    route: String,
    builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

Parameters
startDestination: String

the starting destination's route for this NavGraph

route: String

the destination's unique route

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph

inline operator fun NavigatorProvider.plusAssign(navigator: Navigator<NavDestination>): Unit

Register a navigator using the name provided by the Navigator.Name annotation.

inline operator fun NavGraph.plusAssign(node: NavDestination): Unit

Adds a destination to this NavGraph. The destination must have an id set.

The destination must not have a parent set. If the destination is already part of a NavGraph, call NavGraph.remove before calling this method.

Parameters
node: NavDestination

destination to add

inline operator fun NavGraph.plusAssign(other: NavGraph): Unit

Add all destinations from another collection to this one. As each destination has at most one parent, the destinations will be removed from the given NavGraph.

Parameters
other: NavGraph

collection of destinations to add. All destinations will be removed from the parameter graph after being added to this graph.

inline operator fun NavigatorProvider.set(
    name: String,
    navigator: Navigator<NavDestination>
): Navigator<NavDestination>?

Register a Navigator by name. If a navigator by this name is already registered, this new navigator will replace it.

Returns
Navigator<NavDestination>?

the previously added Navigator for the given name, if any