public interface NavHost

Known direct subclasses
NavHostFragment

NavHostFragment provides an area within your layout for self-contained navigation to occur.

Known indirect subclasses
DynamicNavHostFragment

The NavHostFragment for dynamic features.


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

It is strongly recommended to construct the nav controller by instantiating a NavHostController, which offers additional APIs specifically for a NavHost. The NavHostController should still only be externally accessible as a NavController, rather than directly exposing it as a NavHostController.

Navigation hosts must:

Optionally, a navigation host should consider calling:

Summary

Public methods

abstract @NonNull NavController

The navigation controller for this navigation host.

Extension functions

default final @NonNull NavGraph
NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @IdRes int id,
    @IdRes int startDestination,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder
)

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

default final @NonNull NavGraph
NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @IdRes int id,
    @IdRes int startDestination,
    @ExtensionFunctionType @NonNull Function1<@NonNull DynamicNavGraphBuilderUnit> builder
)

This method is deprecated. Use routes to create your dynamic NavGraph instead

default final @NonNull NavGraph
NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @NonNull String startDestination,
    String route,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder
)

Construct a new NavGraph

default final @NonNull NavGraph
NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @NonNull String startDestination,
    String route,
    @ExtensionFunctionType @NonNull Function1<@NonNull DynamicNavGraphBuilderUnit> builder
)

Construct a new androidx.navigation.NavGraph that supports dynamic navigation destinations

default final @NonNull NavGraph
@ExperimentalSafeArgsApi
NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @NonNull Object startDestination,
    KClass<@NonNull ?> route,
    @NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder
)

Construct a new NavGraph

default final @NonNull NavGraph
@ExperimentalSafeArgsApi
NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @NonNull KClass<@NonNull ?> startDestination,
    KClass<@NonNull ?> route,
    @NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder
)

Construct a new NavGraph

Public methods

getNavController

Added in 1.0.0
abstract @NonNull NavController getNavController()

The navigation controller for this navigation host.

Extension functions

NavHostKt.createGraph

default final @NonNull NavGraph NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @IdRes int id,
    @IdRes int startDestination,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder
)

Construct a new NavGraph

default final @NonNull NavGraph NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @IdRes int id,
    @IdRes int startDestination,
    @ExtensionFunctionType @NonNull Function1<@NonNull DynamicNavGraphBuilderUnit> builder
)

Construct a new androidx.navigation.NavGraph that supports dynamic navigation destinations

NavHostKt.createGraph

default final @NonNull NavGraph NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @NonNull String startDestination,
    String route,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder
)

Construct a new NavGraph

default final @NonNull NavGraph NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @NonNull String startDestination,
    String route,
    @ExtensionFunctionType @NonNull Function1<@NonNull DynamicNavGraphBuilderUnit> builder
)

Construct a new androidx.navigation.NavGraph that supports dynamic navigation destinations

NavHostKt.createGraph

@ExperimentalSafeArgsApi
default final @NonNull NavGraph NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @NonNull Object startDestination,
    KClass<@NonNull ?> route,
    @NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder
)

Construct a new NavGraph

Parameters
@NonNull Object startDestination

the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added as a KClass in order to match.

KClass<@NonNull ?> route

the graph's unique route from a KClass

@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap

A mapping of KType to custom NavType<*> in the route. Only necessary if route uses custom NavTypes.

@ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder

the builder used to construct the graph

NavHostKt.createGraph

@ExperimentalSafeArgsApi
default final @NonNull NavGraph NavHostKt.createGraph(
    @NonNull NavHost receiver,
    @NonNull KClass<@NonNull ?> startDestination,
    KClass<@NonNull ?> route,
    @NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder
)

Construct a new NavGraph

Parameters
@NonNull KClass<@NonNull ?> startDestination

the starting destination's route from a KClass for this NavGraph. The respective NavDestination must be added as a KClass in order to match.

KClass<@NonNull ?> route

the graph's unique route from a KClass

@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap

A mapping of KType to custom NavType<*> in the route. Only necessary if route uses custom NavTypes.

@ExtensionFunctionType @NonNull Function1<@NonNull NavGraphBuilderUnit> builder

the builder used to construct the graph