NavGraph

public class NavGraph extends NavDestination

Object
   ↳ NavDestination
     ↳ 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.

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

Summary

Nested types

NavGraph.Companion

Public fields

final @NonNull SparseArrayCompat<@NonNull NavDestination>
final @NonNull String
final int

The starting destination id for this NavGraph.

final String

The route for the starting destination for this NavGraph.

Public constructors

NavGraph(Navigator<NavGraph> navGraphNavigator)

Public methods

final void

Add all destinations from another collection to this one.

final void

Adds a destination to this NavGraph.

final void

Adds multiple destinations to this NavGraph.

final void

Adds multiple destinations to this NavGraph.

final void

Clear all destinations from this navigation graph.

boolean
equals(Object other)
final NavDestination
findNode(@IdRes int resId)

Finds a destination in the collection by ID.

final NavDestination

Finds a destination in the collection by route.

final @IdRes int

This method is deprecated. Use getStartDestinationId instead.

int
final @NonNull Iterator<@NonNull NavDestination>
void
onInflate(Context context, AttributeSet attrs)

Called when inflating a destination from a resource.

final void

Remove a given destination from this NavGraph

final void
setStartDestination(int startDestId)

Sets the starting destination for this NavGraph.

final void
setStartDestination(String startDestRoute)

Sets the starting destination for this NavGraph.

@NonNull String

Extension functions

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

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

final boolean
NavGraphKt.contains(NavGraph receiver, String route)

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

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

Returns the destination with id.

final @NonNull NavDestination
NavGraphKt.get(NavGraph receiver, String route)

Returns the destination with route.

final void

Removes node from this navigation graph.

final void

Adds a destination to this NavGraph.

final void

Add all destinations from another collection to this one.