NavOptions.Builder


class NavOptions.Builder


Builder for constructing new instances of NavOptions.

Summary

Public constructors

Public functions

NavOptions
NavOptions.Builder

Sets a custom Animation or Animator resource for the enter animation.

NavOptions.Builder

Sets a custom Animation or Animator resource for the exit animation.

NavOptions.Builder

Launch a navigation target as single-top if you are making a lateral navigation between instances of the same target (e.g. detail pages about similar data items) that should not preserve history.

NavOptions.Builder

Sets a custom Animation or Animator resource for the enter animation when popping off the back stack.

NavOptions.Builder

Sets a custom Animation or Animator resource for the exit animation when popping off the back stack.

inline NavOptions.Builder
<T : Any> setPopUpTo(inclusive: Boolean, saveState: Boolean)

Pop up to a given destination before navigating.

NavOptions.Builder
setPopUpTo(destinationId: @IdRes Int, inclusive: Boolean, saveState: Boolean)

Pop up to a given destination before navigating.

NavOptions.Builder
<T : Any> setPopUpTo(route: T, inclusive: Boolean, saveState: Boolean)

Pop up to a given destination before navigating.

NavOptions.Builder
setPopUpTo(route: String?, inclusive: Boolean, saveState: Boolean)

Pop up to a given destination before navigating.

NavOptions.Builder
setRestoreState(restoreState: Boolean)

Whether this navigation action should restore any state previously saved by setPopUpTo or the popUpToSaveState attribute.

Public constructors

Builder

Added in 1.0.0
Builder()

Public functions

build

Added in 1.0.0
fun build(): NavOptions
Returns
NavOptions

a constructed NavOptions

setEnterAnim

Added in 1.0.0
fun setEnterAnim(enterAnim: @AnimRes @AnimatorRes Int): NavOptions.Builder

Sets a custom Animation or Animator resource for the enter animation.

Note: Animator resources are not supported for navigating to a new Activity

Parameters
enterAnim: @AnimRes @AnimatorRes Int

Custom animation to run

Returns
NavOptions.Builder

this Builder

See also
enterAnim

setExitAnim

Added in 1.0.0
fun setExitAnim(exitAnim: @AnimRes @AnimatorRes Int): NavOptions.Builder

Sets a custom Animation or Animator resource for the exit animation.

Note: Animator resources are not supported for navigating to a new Activity

Parameters
exitAnim: @AnimRes @AnimatorRes Int

Custom animation to run

Returns
NavOptions.Builder

this Builder

See also
exitAnim

setLaunchSingleTop

Added in 1.0.0
fun setLaunchSingleTop(singleTop: Boolean): NavOptions.Builder

Launch a navigation target as single-top if you are making a lateral navigation between instances of the same target (e.g. detail pages about similar data items) that should not preserve history.

Parameters
singleTop: Boolean

true to launch as single-top

setPopEnterAnim

Added in 1.0.0
fun setPopEnterAnim(popEnterAnim: @AnimRes @AnimatorRes Int): NavOptions.Builder

Sets a custom Animation or Animator resource for the enter animation when popping off the back stack.

Note: Animator resources are not supported for navigating to a new Activity

Parameters
popEnterAnim: @AnimRes @AnimatorRes Int

Custom animation to run

Returns
NavOptions.Builder

this Builder

See also
popEnterAnim

setPopExitAnim

Added in 1.0.0
fun setPopExitAnim(popExitAnim: @AnimRes @AnimatorRes Int): NavOptions.Builder

Sets a custom Animation or Animator resource for the exit animation when popping off the back stack.

Note: Animator resources are not supported for navigating to a new Activity

Parameters
popExitAnim: @AnimRes @AnimatorRes Int

Custom animation to run

Returns
NavOptions.Builder

this Builder

See also
popExitAnim

setPopUpTo

inline fun <T : Any> setPopUpTo(inclusive: Boolean, saveState: Boolean = false): NavOptions.Builder

Pop up to a given destination before navigating. This pops all non-matching destinations from the back stack until this destination is found.

Parameters
<T : Any>

route from a KClass for destination to pop up to, clearing all intervening destinations.

inclusive: Boolean

true to also pop the given destination from the back stack.

saveState: Boolean = false

true if the back stack and the state of all destinations between the current destination and T should be saved for later restoration via setRestoreState or the restoreState attribute using the same route from KClass as popUpToRouteClass (note: this matching route is true whether inclusive is true or false).

Returns
NavOptions.Builder

this Builder

setPopUpTo

Added in 2.4.0
fun setPopUpTo(
    destinationId: @IdRes Int,
    inclusive: Boolean,
    saveState: Boolean = false
): NavOptions.Builder

Pop up to a given destination before navigating. This pops all non-matching destinations from the back stack until this destination is found.

Parameters
destinationId: @IdRes Int

The destination to pop up to, clearing all intervening destinations.

inclusive: Boolean

true to also pop the given destination from the back stack.

saveState: Boolean = false

true if the back stack and the state of all destinations between the current destination and destinationId should be saved for later restoration via setRestoreState or the restoreState attribute using the same ID as popUpToId (note: this matching ID is true whether inclusive is true or false).

Returns
NavOptions.Builder

this Builder

setPopUpTo

Added in 2.8.0
fun <T : Any> setPopUpTo(route: T, inclusive: Boolean, saveState: Boolean = false): NavOptions.Builder

Pop up to a given destination before navigating. This pops all non-matching destinations from the back stack until this destination is found.

Parameters
route: T

route from an Object for destination to pop up to, clearing all intervening destinations.

inclusive: Boolean

true to also pop the given destination from the back stack.

saveState: Boolean = false

true if the back stack and the state of all destinations between the current destination and route should be saved for later restoration via setRestoreState or the restoreState attribute using the same route from an Object as popUpToRouteObject (note: this matching route is true whether inclusive is true or false).

Returns
NavOptions.Builder

this Builder

setPopUpTo

Added in 2.4.0
fun setPopUpTo(route: String?, inclusive: Boolean, saveState: Boolean = false): NavOptions.Builder

Pop up to a given destination before navigating. This pops all non-matching destinations from the back stack until this destination is found.

Parameters
route: String?

route for destination to pop up to, clearing all intervening destinations.

inclusive: Boolean

true to also pop the given destination from the back stack.

saveState: Boolean = false

true if the back stack and the state of all destinations between the current destination and route should be saved for later restoration via setRestoreState or the restoreState attribute using the same ID as popUpToRoute (note: this matching ID is true whether inclusive is true or false).

Returns
NavOptions.Builder

this Builder

setRestoreState

Added in 2.4.0
fun setRestoreState(restoreState: Boolean): NavOptions.Builder

Whether this navigation action should restore any state previously saved by setPopUpTo or the popUpToSaveState attribute. If no state was previously saved with the destination ID being navigated to, this has no effect.