Android 12 Developer Preview is here! Try it out, and give us your feedback!

NavController

open class NavController
kotlin.Any
   ↳ androidx.navigation.NavController

NavController manages app navigation within a NavHost.

Apps will generally obtain a controller directly from a host, or by using one of the utility methods on the Navigation class rather than create a controller directly.

Navigation flows and destinations are determined by the navigation graph owned by the controller. These graphs are typically inflated from an Android resource, but, like views, they can also be constructed or combined programmatically or for the case of dynamic navigation structure. (For example, if the navigation structure of the application is determined by live data obtained' from a remote server.)

Summary

Nested classes
abstract

OnDestinationChangedListener receives a callback when the getCurrentDestination() or its arguments change.

Constants
static String

The Intent that triggered a deep link to the current destination.

Public constructors
<init>(@NonNull context: Context)

Constructs a new controller for a given Context.

Public methods
open Unit

Adds an OnDestinationChangedListener to this controller to receive a callback whenever the getCurrentDestination() or its arguments change.

open NavDeepLinkBuilder

Create a deep link to a destination within this NavController.

open NavBackStackEntry
getBackStackEntry(@IdRes destinationId: Int)

Gets the topmost NavBackStackEntry for a destination id.

open NavBackStackEntry?

Gets the topmost NavBackStackEntry.

open NavDestination?

Gets the current destination.

open NavGraph

Gets the topmost navigation graph associated with this NavController.

open NavInflater

Returns the inflater for this controller.

open NavigatorProvider

Retrieve the NavController's NavigatorProvider.

open NavBackStackEntry?

Gets the previous visible NavBackStackEntry.

open ViewModelStoreOwner
getViewModelStoreOwner(@IdRes navGraphId: Int)

Gets the ViewModelStoreOwner for a NavGraph.

open Boolean
handleDeepLink(@Nullable intent: Intent?)

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

open Unit
navigate(@IdRes resId: Int)

Navigate to a destination from the current navigation graph.

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

Navigate to a destination from the current navigation graph.

open Unit
navigate(@IdRes resId: Int, @Nullable args: Bundle?, @Nullable navOptions: NavOptions?)

Navigate to a destination from the current navigation graph.

open Unit
navigate(@IdRes resId: Int, @Nullable args: Bundle?, @Nullable navOptions: NavOptions?, @Nullable navigatorExtras: Navigator.Extras?)

Navigate to a destination from the current navigation graph.

open Unit
navigate(@NonNull deepLink: Uri)

Navigate to a destination via the given deep link Uri.

open Unit
navigate(@NonNull deepLink: Uri, @Nullable navOptions: NavOptions?)

Navigate to a destination via the given deep link Uri.

open Unit
navigate(@NonNull deepLink: Uri, @Nullable navOpti