TestNavHostController


public final class TestNavHostController extends NavHostController


Subclass of NavHostController that offers additional APIs for testing Navigation.

Summary

Public constructors

Public methods

final @NonNull List<@NonNull NavBackStackEntry>

Gets an immutable copy of the elements 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.

Inherited methods

From androidx.navigation.NavController
void
final boolean
final boolean
final boolean
@MainThread
<T extends Object> clearBackStack(@NonNull T route)
final boolean
final @NonNull NavBackStackEntry
<T extends Object> getBackStackEntry()
final @NonNull NavBackStackEntry
<T extends Object> getBackStackEntry(@NonNull KClass<@NonNull T> route)
final @NonNull NavBackStackEntry
<T extends Object> getBackStackEntry(@NonNull T route)
final @NonNull NavBackStackEntry
NavBackStackEntry
final @NonNull Flow<@NonNull NavBackStackEntry>
NavDestination
@NonNull NavGraph
@NonNull NavigatorProvider
NavBackStackEntry
final @NonNull StateFlow<@NonNull List<@NonNull NavBackStackEntry>>
final boolean
void
void
void
@MainThread
navigate(@NonNull NavUri deepLink, NavOptions navOptions)
void
final void
@MainThread
<T extends Object> navigate(
    @NonNull T route,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavOptionsBuilderUnit> builder
)
final void
@MainThread
navigate(
    @NonNull String route,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavOptionsBuilderUnit> builder
)
void
@MainThread
navigate(
    @NonNull NavUri deepLink,
    NavOptions navOptions,
    Navigator.Extras navigatorExtras
)
void
@MainThread
navigate(
    @NonNull NavDeepLinkRequest request,
    NavOptions navOptions,
    Navigator.Extras navigatorExtras
)
final void
@MainThread
<T extends Object> navigate(
    @NonNull T route,
    NavOptions navOptions,
    Navigator.Extras navigatorExtras
)
final void
@MainThread
navigate(
    @NonNull String route,
    NavOptions navOptions,
    Navigator.Extras navigatorExtras
)
boolean
boolean
final boolean
@MainThread
<T extends Object> popBackStack(boolean inclusive, boolean saveState)
final boolean
@MainThread
<T extends Object> popBackStack(
    @NonNull KClass<@NonNull T> route,
    boolean inclusive,
    boolean saveState
)
final boolean
@MainThread
<T extends Object> popBackStack(
    @NonNull T route,
    boolean inclusive,
    boolean saveState
)
final boolean
@MainThread
popBackStack(@NonNull String route, boolean inclusive, boolean saveState)
void
void
SavedState
void
void
@MainThread
@CallSuper
setGraph(@NonNull NavGraph graph, SavedState startDestinationArgs)
From androidx.navigation.NavHostController
final void
final void

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 NavBackStackEntrygetBackStack()

Gets an immutable copy of the elements 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.