The Android Developer Challenge is back! Submit your idea before December 2.

NavAction

class NavAction
kotlin.Any
   ↳ androidx.navigation.NavAction

Navigation actions provide a level of indirection between your navigation code and the underlying destinations. This allows you to define common actions that change their destination or NavOptions based on the current NavDestination.

The NavOptions associated with a NavAction are used by default when navigating to this action via NavController#navigate(int) or NavController#navigate(int, Bundle).

Actions should be added via NavDestination#putAction(int, int) or NavDestination#putAction(int, NavAction).

Summary

Public constructors

<init>(@IdRes destinationId: Int)

Creates a new NavAction for the given destination.

<init>(@IdRes destinationId: Int, @Nullable navOptions: NavOptions?)

Creates a new NavAction for the given destination.

<init>(@IdRes destinationId: Int, @Nullable navOptions: NavOptions?, @Nullable defaultArgs: Bundle?)

Creates a new NavAction for the given destination.

Public methods

Bundle?

Gets the argument bundle to be used by default when navigating to this action.

Int

Gets the ID of the destination that should be navigated to when this action is used

NavOptions?

Gets the NavOptions to be used by default when navigating to this action.

Unit
setDefaultArguments(@Nullable defaultArgs: Bundle?)

Sets the argument bundle to be used by default when navigating to this action.

Unit
setNavOptions(@Nullable navOptions: NavOptions?)

Sets the NavOptions to be used by default when navigating to this action.

Public constructors

<init>

NavAction(@IdRes destinationId: Int)

Creates a new NavAction for the given destination.

Parameters
destinationId Int: the ID of the destination that should be navigated to when this action is used.

<init>

NavAction(@IdRes destinationId: Int, @Nullable navOptions: NavOptions?)

Creates a new NavAction for the given destination.

Parameters
destinationId Int: the ID of the destination that should be navigated to when this action is used.
navOptions Int: special options for this action that should be used by default

<init>

NavAction(@IdRes destinationId: Int, @Nullable navOptions: NavOptions?, @Nullable defaultArgs: Bundle?)

Creates a new NavAction for the given destination.

Parameters
destinationId Int: the ID of the destination that should be navigated to when this action is used.
navOptions Int: special options for this action that should be used by default
defaultArgs Int: argument bundle to be used by default

Public methods

getDefaultArguments

@Nullable fun getDefaultArguments(): Bundle?

Gets the argument bundle to be used by default when navigating to this action.

Return
Bundle?: bundle of default argument values

getDestinationId

fun getDestinationId(): Int

Gets the ID of the destination that should be navigated to when this action is used

getNavOptions

@Nullable fun getNavOptions(): NavOptions?

Gets the NavOptions to be used by default when navigating to this action.

setDefaultArguments

fun setDefaultArguments(@Nullable defaultArgs: Bundle?): Unit

Sets the argument bundle to be used by default when navigating to this action.

Parameters
defaultArgs Bundle?: argument bundle that should be used by default

setNavOptions

fun setNavOptions(@Nullable navOptions: NavOptions?): Unit

Sets the NavOptions to be used by default when navigating to this action.

Parameters
navOptions NavOptions?: special options for this action that should be used by default