TestNavHostController


public final class TestNavHostController


Subclass of NavHostController that offers additional APIs for testing Navigation.

Summary

Public constructors

Public methods

final @NonNull List<@NonNull <Error class: unknown class>>

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

final void
setCurrentDestination(@IdRes int destId, @NonNull Bundle args)

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

final void

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

Public constructors

TestNavHostController

Added in 2.3.0
public TestNavHostController(@NonNull Context context)

Public methods

getBackStack

Added in 2.3.0
public final @NonNull List<@NonNull <Error class: unknown class>getBackStack()

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

setCurrentDestination

Added in 2.3.0
public final void setCurrentDestination(@IdRes int destId, @NonNull Bundle args)

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
@IdRes int destId

The destination id to navigate to.

@NonNull Bundle args

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
public final void setCurrentDestination(@NonNull String destRoute, @NonNull Bundle args)

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
@NonNull String destRoute

The destination route to navigate to.

@NonNull Bundle args

The arguments to pass to the destination.

Throws
java.lang.IllegalArgumentException

If the destination does not exist on the NavGraph.