TestNavHostController


  • Common/All
  • Android/JVM

Subclass of NavHostController that offers additional APIs for testing Navigation.

Summary

Public constructors

android

Public functions

Unit

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

android
Unit
setCurrentDestination(destRoute: String, args: Bundle)

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

android

Public properties

List<NavBackStackEntry>

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

android

Inherited functions

open Unit
android
inline Boolean
android
Boolean

Clears any saved state associated with destinationId that was previously saved via popBackStack when using a saveState value of true.

android
Boolean
@MainThread
<T : Any> clearBackStack(route: KClass<T>)
android
Boolean
@MainThread
<T : Any> clearBackStack(route: T)
android
Boolean
android
open NavDeepLinkBuilder

Create a deep link to a destination within this NavController.

android
inline NavBackStackEntry
android
open NavBackStackEntry
getBackStackEntry(destinationId: @IdRes Int)

Gets the topmost NavBackStackEntry for a destination id.

android
NavBackStackEntry
<T : Any> getBackStackEntry(route: KClass<T>)
android
NavBackStackEntry
<T : Any> getBackStackEntry(route: T)
android
NavBackStackEntry
android
open ViewModelStoreOwner

Gets the ViewModelStoreOwner for a NavGraph.

android
open Boolean

Checks the given Intent for a Navigation deep link and navigates to the deep link if present.

android
Boolean
android
open Unit
@MainThread
navigate(deepLink: Uri)
android
open Unit

Navigate via the given NavDirections

android
open Unit
android
open Unit

Navigate to a destination from the current navigation graph.

android
open Unit
@MainThread
navigate(deepLink: Uri, navOptions: NavOptions?)
android
open Unit
@MainThread
navigate(directions: NavDirections, navOptions: NavOptions?)

Navigate via the given NavDirections

android
open Unit
@MainThread
navigate(directions: NavDirections, navigatorExtras: Navigator.Extras)

Navigate via the given NavDirections

android
open Unit
android
open Unit
@MainThread
navigate(resId: @IdRes Int, args: Bundle?)

Navigate to a destination from the current navigation graph.

android
Unit
@MainThread
<T : Any> navigate(route: T, builder: NavOptionsBuilder.() -> Unit)
android
Unit
@MainThread
navigate(route: String, builder: NavOptionsBuilder.() -> Unit)
android
open Unit
@MainThread
navigate(
    deepLink: Uri,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)
android
open Unit
@MainThread
navigate(
    request: NavDeepLinkRequest,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)
android
open Unit
@MainThread
navigate(resId: @IdRes Int, args: Bundle?, navOptions: NavOptions?)

Navigate to a destination from the current navigation graph.

android
Unit
@MainThread
<T : Any> navigate(
    route: T,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)
android
Unit
@MainThread
navigate(
    route: String,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)
android
open Unit
@MainThread
navigate(
    resId: @IdRes Int,
    args: Bundle?,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
)

Navigate to a destination from the current navigation graph.

android
open Boolean
android
open Boolean
android
open Boolean
@MainThread
popBackStack(destinationId: @IdRes Int, inclusive: Boolean)

Attempts to pop the controller's back stack back to a specific destination.

android
inline Boolean
@MainThread
<T : Any> popBackStack(inclusive: Boolean, saveState: Boolean)
android
open Boolean
@MainThread
popBackStack(
    destinationId: @IdRes Int,
    inclusive: Boolean,
    saveState: Boolean
)

Attempts to pop the controller's back stack back to a specific destination.

android
Boolean
@MainThread
<T : Any> popBackStack(
    route: KClass<T>,
    inclusive: Boolean,
    saveState: Boolean
)
android
Boolean
@MainThread
<T : Any> popBackStack(route: T, inclusive: Boolean, saveState: Boolean)
android
Boolean
@MainThread
popBackStack(route: String, inclusive: Boolean, saveState: Boolean)
android
open Unit
android
open Unit
android
open Bundle?
android
open Unit

Sets the navigation graph to the specified resource.

android
open Unit
@MainThread
@CallSuper
setGraph(graph: NavGraph, startDestinationArgs: Bundle?)
android
open Unit
@MainThread
@CallSuper
setGraph(graphResId: @NavigationRes Int, startDestinationArgs: Bundle?)

Sets the navigation graph to the specified resource.

android
final Unit

Set whether the NavController should handle the system Back button events via the registered OnBackPressedDispatcher.

android
final Unit
android
final Unit

Sets the host's OnBackPressedDispatcher.

android
final Unit
android

Public constructors

TestNavHostController

TestNavHostController(context: Context)

Public functions

setCurrentDestination

fun setCurrentDestination(destId: @IdRes Int, args: Bundle = savedState()): 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 = savedState()

The arguments to pass to the destination.

Throws
java.lang.IllegalArgumentException

If the destination does not exist on the NavGraph.

setCurrentDestination

fun setCurrentDestination(destRoute: String, args: Bundle = savedState()): 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 = savedState()

The arguments to pass to the destination.

Throws
java.lang.IllegalArgumentException

If the destination does not exist on the NavGraph.

Public properties

backStack

val backStackList<NavBackStackEntry>

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