public class NavGraph extends NavDestination implements Iterable

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 getStartDestination to be added to the back stack.

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

Summary

Extension functions

final boolean

NavGraphKt.contains(@NonNull NavGraph receiver, @IdRes int id)

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

final boolean

<T extends Object> NavGraphKt.contains(
    @NonNull NavGraph receiver,
    @NonNull KClass<@NonNull T> route
)

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

final boolean

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

final boolean

<T extends Object> NavGraphKt.contains(@NonNull NavGraph receiver, @NonNull T route)

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

final @NonNull NavDestination

NavGraphKt.get(@NonNull NavGraph receiver, @IdRes int id)

Returns the destination with id.

final @NonNull NavDestination

<T extends Object> NavGraphKt.get(
    @NonNull NavGraph receiver,
    @NonNull KClass<@NonNull T> route
)

Returns the destination with route from KClass.

final @NonNull NavDestination

Returns the destination with route.

final @NonNull NavDestination

<T extends Object> NavGraphKt.get(@NonNull NavGraph receiver, @NonNull T route)

Returns the destination with route from an Object.

final void

NavGraphKt.minusAssign(
    @NonNull NavGraph receiver,
    @NonNull NavDestination node
)

Removes node from this navigation graph.

final void

NavGraphKt.plusAssign(
    @NonNull NavGraph receiver,
    @NonNull NavDestination node
)

Adds a destination to this NavGraph.

final void

Add all destinations from another collection to this one.

Public constructors

Public methods

addAll

public final void addAll(@NonNull NavGraph other)

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
@NonNull NavGraph other

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

clear

public final void clear()

Clear all destinations from this navigation graph.

findNode

public final NavDestination <T extends Object> findNode()

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

Returns
NavDestination

the node with route - the node must have been created with a route from KClass

findNode

public final NavDestination findNode(@IdRes int resId)

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
@IdRes int resId

ID to locate

findNode

public final NavDestination <T extends Object> findNode(T route)

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

Parameters
T route

Route to locate

Returns
NavDestination

the node with route - the node must have been created with a route from KClass

findNode

public final NavDestination findNode(String route)

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

Parameters
String route

Route to locate

findNodeComprehensive

public final NavDestination findNodeComprehensive(
    int resId,
    NavDestination lastVisited,
    boolean searchChildren,
    NavDestination matchingDest
)

Searches all children and parents recursively.

Does not revisit graphs (whether it's a child or parent) if it has already been visited.

Parameters
int resId

the NavDestination.id

NavDestination lastVisited

the previously visited node

boolean searchChildren

searches the graph's children for the node when true

NavDestination matchingDest

an optional NavDestination that the node should match with. This is because resId is only unique to a local graph. Nodes in sibling graphs can have the same id.

getStartDestination

public final @IdRes int getStartDestination()

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

Returns
@IdRes int

the start destination

getStartDestinationId

public final @IdRes int getStartDestinationId()

The starting destination id for this NavGraph. When navigating to the NavGraph, the destination represented by this id is the one the user will initially see.

getStartDestinationRoute

public final String getStartDestinationRoute()

The route for the starting destination for this NavGraph. When navigating to the NavGraph, the destination represented by this route is the one the user will initially see.

setStartDestination

public final void <T extends Object> setStartDestination()

Sets the starting destination for this NavGraph.

This will override any previously set startDestinationId

Parameters
<T extends Object>

The route of the destination as a KClass to be shown when navigating to this NavGraph.

setStartDestination

public final void setStartDestination(int startDestId)

Sets the starting destination for this NavGraph.

This will clear any previously set startDestinationRoute.

Parameters
int startDestId

The id of the destination to be shown when navigating to this NavGraph.

Extension functions

NavGraphKt.plusAssign

public final void NavGraphKt.plusAssign(@NonNull NavGraph receiver, @NonNull NavGraph other)

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
@NonNull NavGraph other

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

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.