interface NavHost

Known direct subclasses
NavHostFragment

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


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 properties

NavController

The navigation controller for this navigation host.

Extension functions

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

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

inline NavGraph
NavHost.createGraph(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: DynamicNavGraphBuilder.() -> Unit
)

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

inline NavGraph
NavHost.createGraph(
    startDestination: String,
    route: String?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

inline NavGraph
NavHost.createGraph(
    startDestination: String,
    route: String?,
    builder: DynamicNavGraphBuilder.() -> Unit
)

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

inline NavGraph
NavHost.createGraph(
    startDestination: Any,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

inline NavGraph
NavHost.createGraph(
    startDestination: Any,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: DynamicNavGraphBuilder.() -> Unit
)

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

inline NavGraph
NavHost.createGraph(
    startDestination: KClass<*>,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

inline NavGraph
NavHost.createGraph(
    startDestination: KClass<*>,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: DynamicNavGraphBuilder.() -> Unit
)

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

Public properties

Added in 1.0.0
val navControllerNavController

The navigation controller for this navigation host.

Extension functions

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

Construct a new NavGraph

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

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

inline fun NavHost.createGraph(
    startDestination: String,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

inline fun NavHost.createGraph(
    startDestination: String,
    route: String? = null,
    builder: DynamicNavGraphBuilder.() -> Unit
): NavGraph

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

inline fun NavHost.createGraph(
    startDestination: Any,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: Any

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

route: KClass<*>? = null

the graph's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

inline fun NavHost.createGraph(
    startDestination: Any,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: DynamicNavGraphBuilder.() -> Unit
): NavGraph

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

Parameters
startDestination: Any

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

route: KClass<*>? = null

the graph's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: DynamicNavGraphBuilder.() -> Unit

the builder used to construct the graph

inline fun NavHost.createGraph(
    startDestination: KClass<*>,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: KClass<*>

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

route: KClass<*>? = null

the graph's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

inline fun NavHost.createGraph(
    startDestination: KClass<*>,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: DynamicNavGraphBuilder.() -> Unit
): NavGraph

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

Parameters
startDestination: KClass<*>

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

route: KClass<*>? = null

the graph's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: DynamicNavGraphBuilder.() -> Unit

the builder used to construct the graph