Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

androidx.navigation

Classes

ActionOnlyNavDirections

An implementation of NavDirections without any arguments.

ActivityNavigator

ActivityNavigator implements cross-activity navigation.

ActivityNavigatorDestinationBuilder

DSL for constructing a new ActivityNavigator.Destination

AnimBuilder

DSL for setting custom Animation or Animator resources on a NavOptionsBuilder

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 android.support.v4.app.Fragment.navArgs.

NavArgument

NavArgument denotes an argument that is supported by a NavDestination.

NavArgumentBuilder

DSL for constructing a new NavArgument

NavController

NavController manages app navigation within a NavHost.

NavDeepLinkBuilder

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

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.

Navigation

Entry point for navigation operations.

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.

NavInflater

Class which translates a navigation XML file into a NavGraph

NavOptions

NavOptions stores special options for navigate actions

NavOptionsBuilder

DSL for constructing a new NavOptions

NavType

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

PopUpToBuilder

DSL for customizing NavOptionsBuilder.popUpTo operations.

Annotations

NavDestinationDsl

NavOptionsDsl

Top-level functions summary

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

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

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

Construct a new NavOptions

Extension functions summary

For android.app.Activity
NavController
Activity.findNavController(@IdRes viewId: Int)

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

NavArgsLazy<Args>

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

For android.view.View
NavController

Find a NavController associated with a View.

For NavGraphBuilder
Unit

Construct a new ActivityNavigator.Destination

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

Construct a nested NavGraph

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

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

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

Returns the destination with id.

operator Unit

Removes node from this navigation graph.

operator Unit

Adds a destination to this NavGraph.

operator Unit

Add all destinations from another collection to this one.

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

Construct a new NavGraph

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

Construct a new NavGraph

For NavigatorProvider
operator T

Retrieves a registered Navigator by name.

operator T

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

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

Construct a new NavGraph

operator Unit

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

operator Navigator<out NavDestination!>?

Register a Navigator by name.

For Fragment
Lazy<VM>
Fragment.navGraphViewModels(@IdRes navGraphId: Int, noinline factoryProducer: () -> ViewModelProvider.Factory = null)

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

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 Optional ActivityOptionsCompat to pass through to android.support.v4.app.ActivityCompat.startActivity.
flags Intent.FLAG_ACTIVITY_ flags to add to the Intent.

navOptions

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

Construct a new NavOptions

Extension functions

activity

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

Construct a new ActivityNavigator.Destination

contains

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

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

createGraph

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

Construct a new NavGraph

createGraph

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

Construct a new NavGraph

findNavController

fun Activity.findNavController(@IdRes viewId: 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

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

get

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

Returns the destination with id.

Exceptions
IllegalArgumentException if no destination is found with that id.

get

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

Retrieves a registered Navigator by name.

Exceptions
IllegalStateException if the Navigator has not been added

get

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

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

Exceptions
IllegalStateException if the Navigator has not been added

minusAssign

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

Removes node from this navigation graph.

navArgs

@MainThread inline fun <reified 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.

navGraphViewModels

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

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


class MyFragment : Fragment() {
    val viewmodel: MainViewModel by navGraphViewModels(R.navigation.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.navigation.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 ID of a NavGraph that exists on the {@link NavController} back stack

navigation

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

Construct a nested NavGraph

navigation

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

Construct a new NavGraph

plusAssign

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 destination to add

plusAssign

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 collection of destinations to add. All destinations will be removed from the parameter graph after being added to this graph.

plusAssign

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

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

set

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

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

Return
the previously added Navigator for the given name, if any