NavGraph

open class NavGraph : NavDestination, MutableIterable<NavDestination!>
kotlin.Any
   ↳ androidx.navigation.NavDestination
   ↳ androidx.navigation.NavGraph

NavGraph is a collection of NavDestination nodes fetchable by ID.

A NavGraph serves as a 'virtual' destination: while the NavGraph itself will not appear on the back stack, navigating to the NavGraph will cause the starting destination to be added to the back stack.

Summary

Public constructors
<init>(navigatorProvider: NavigatorProvider)

Construct a new NavGraph.

<init>(navGraphNavigator: Navigator<out NavGraph!>)

Construct a new NavGraph.

Public methods
open Unit
addAll(other: NavGraph)

Add all destinations from another collection to this one.

open Unit

Clear all destinations from this navigation graph.

open Unit
onInflate(context: Context, attrs: AttributeSet)

open Int

Returns the starting destination for this NavGraph.

open MutableIterator<NavDestination!>

open Unit

Adds multiple destinations to this NavGraph.

open Unit

Adds multiple destinations to this NavGraph.

open Unit

Remove a given destination from this NavGraph

open Unit

Adds a destination to this NavGraph.

open NavDestination!
findNode(resid: Int)

Finds a destination in the collection by ID.

open Unit
setStartDestination(startDestId: Int)

Sets the starting destination for this NavGraph.

Inherited functions
Extension functions
From androidx.navigation
operator NavDestination

Returns the destination with id.

operator Boolean

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

operator Unit

Adds a destination to this NavGraph.

operator Unit

Add all destinations from another collection to this one.

operator Unit

Removes node from this navigation graph.

Public constructors

<init>

NavGraph(navigatorProvider: NavigatorProvider)

Construct a new NavGraph. This NavGraph is not valid until you add a destination and set the starting destination.

Parameters
navigatorProvider NavigatorProvider: The NavController which this NavGraph will be associated with.

<init>

NavGraph(navGraphNavigator: Navigator<out NavGraph!>)

Construct a new NavGraph. This NavGraph is not valid until you add a destination and set the starting destination.

Parameters
navGraphNavigator Navigator<out NavGraph!>: The NavGraphNavigator which this destination will be associated with. Generally retrieved via a NavController's NavigatorProvider#getNavigator(Class) method.

Public methods

addAll

open fun addAll(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 this graph after being added to this graph.

clear

open fun clear(): Unit

Clear all destinations from this navigation graph.

onInflate

open fun onInflate(context: Context, attrs: AttributeSet): Unit

getStartDestination

open fun getStartDestination(): Int

Returns the starting destination for this NavGraph. When navigating to the NavGraph, this destination is the one the user will initially see.

Return
Int:

iterator

open fun iterator(): MutableIterator<NavDestination!>

addDestinations

open fun addDestinations(nodes: MutableCollection<NavDestination!>): Unit

Adds multiple destinations to this NavGraph. Each destination must have an NavDestination#getId() id} set.

Each destination must not have a parent set. If any destination is already part of a navigation graph, call #remove(NavDestination) before calling this method.

Parameters
nodes MutableCollection<NavDestination!>: destinations to add

addDestinations

open fun addDestinations(vararg nodes: NavDestination!): Unit

Adds multiple destinations to this NavGraph. Each destination must have an NavDestination#getId() id} set.

Each destination must not have a parent set. If any destination is already part of a navigation graph, call #remove(NavDestination) before calling this method.

Parameters
nodes NavDestination!: destinations to add

remove

open fun remove(node: NavDestination): Unit

Remove a given destination from this NavGraph

Parameters
node NavDestination: the destination to remove.

addDestination

open fun addDestination(node: NavDestination): Unit

Adds a destination to this NavGraph. The destination must have an NavDestination#getId() id} set.

The destination must not have a parent set. If the destination is already part of a navigation graph, call #remove(NavDestination) before calling this method.

Parameters
node NavDestination: destination to add

findNode

open fun findNode(resid: Int): NavDestination!

Finds a destination in the collection by ID. This will recursively check the parent of this navigation graph if node is not found in this navigation graph.

Parameters
resid Int: ID to locate
Return
NavDestination!: the node with ID resid

setStartDestination

open fun setStartDestination(startDestId: Int): Unit

Sets the starting destination for this NavGraph.

Parameters
startDestId Int: The id of the destination to be shown when navigating to this NavGraph.