TestNavHostController


class TestNavHostController : NavHostController


Subclass of NavHostController that offers additional APIs for testing Navigation.

Summary

Public constructors

Public functions

Unit

Navigate directly to any destination on the current androidx.navigation.NavGraph via an explicit deep link.

Unit
setCurrentDestination(destRoute: String, args: Bundle)

Navigate directly to any destination on the current androidx.navigation.NavGraph via an explicit deep link.

Public properties

List<NavBackStackEntry>

Gets an immutable copy of the elements currently on the back stack.

Inherited functions

From androidx.navigation.NavController
open Unit
inline Boolean
Boolean
@MainThread
<T : Any> clearBackStack(route: KClass<T>)
Boolean
@MainThread
<T : Any> clearBackStack(route: T)
Boolean
inline NavBackStackEntry
NavBackStackEntry
<T : Any> getBackStackEntry(route: KClass<T>)
NavBackStackEntry
<T : Any> getBackStackEntry(route: T)
NavBackStackEntry
Boolean
open Unit
open Unit
open Unit
@MainThread
navigate(deepLink: NavUri, navOptions: NavOptions?)
open Unit
Unit
@MainThread
<T : Any> navigate(route: T, builder: NavOptionsBuilder.() -> Unit)
Unit
@MainThread
navigate(route: String, builder: NavOptionsBuilder.() -> Unit)
open Unit
@MainThread
navigate(
    deepLink: NavUri,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)
open Unit
@MainThread
navigate(
    request: NavDeepLinkRequest,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)
Unit
@MainThread
<T : Any> navigate(
    route: T,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)
Unit
@MainThread
navigate(
    route: String,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)
open Boolean
open Boolean
inline Boolean
@MainThread
<T : Any> popBackStack(inclusive: Boolean, saveState: Boolean)
Boolean
@MainThread
<T : Any> popBackStack(
    route: KClass<T>,
    inclusive: Boolean,
    saveState: Boolean
)
Boolean
@MainThread
<T : Any> popBackStack(route: T, inclusive: Boolean, saveState: Boolean)
Boolean
@MainThread
popBackStack(route: String, inclusive: Boolean, saveState: Boolean)
open Unit
open Unit
open SavedState?
open Unit
@MainThread
@CallSuper
setGraph(graph: NavGraph, startDestinationArgs: SavedState?)
From androidx.navigation.NavHostController

Public constructors

TestNavHostController

Added in 2.3.0
TestNavHostController(context: Context)

Public functions

setCurrentDestination

Added in 2.3.0
fun setCurrentDestination(destId: @IdRes Int, args: Bundle = Bundle()): Unit

Navigate directly to any destination on the current androidx.navigation.NavGraph via an explicit deep link. If an implicit deep link exists for this destination use #navigate(Uri) instead.

Parameters
destId: @IdRes Int

The destination id to navigate to.

args: Bundle = Bundle()

The arguments to pass to the destination.

Throws
java.lang.IllegalArgumentException

If the destination does not exist on the NavGraph.

setCurrentDestination

Added in 2.4.0
fun setCurrentDestination(destRoute: String, args: Bundle = Bundle()): Unit

Navigate directly to any destination on the current androidx.navigation.NavGraph via an explicit deep link. If an implicit deep link exists for this destination use #navigate(Uri) instead.

Parameters
destRoute: String

The destination route to navigate to.

args: Bundle = Bundle()

The arguments to pass to the destination.

Throws
java.lang.IllegalArgumentException

If the destination does not exist on the NavGraph.

Public properties

backStack

Added in 2.3.0
val backStackList<NavBackStackEntry>

Gets an immutable copy of the elements currently on the back stack.