Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

NavOptions.Builder

public static final class NavOptions.Builder
extends Object

java.lang.Object
   ↳ androidx.navigation.NavOptions.Builder


Builder for constructing new instances of NavOptions.

Summary

Public constructors

NavOptions.Builder()

Public methods

NavOptions build()
NavOptions.Builder setEnterAnim(int enterAnim)

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

NavOptions.Builder setExitAnim(int exitAnim)

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

NavOptions.Builder setLaunchSingleTop(boolean singleTop)

Launch a navigation target as single-top if you are making a lateral navigation between instances of the same target (e.g.

NavOptions.Builder setPopEnterAnim(int popEnterAnim)

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

NavOptions.Builder setPopExitAnim(int popExitAnim)

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

NavOptions.Builder setPopUpTo(int destinationId, boolean inclusive)

Pop up to a given destination before navigating.

Inherited methods

Public constructors

public NavOptions.Builder ()

Public methods

build

public NavOptions build ()

Returns
NavOptions a constructed NavOptions

setEnterAnim

public NavOptions.Builder setEnterAnim (int enterAnim)

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 int: Custom animation to run

Returns
NavOptions.Builder this Builder

setExitAnim

public NavOptions.Builder setExitAnim (int exitAnim)

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 int: Custom animation to run

Returns
NavOptions.Builder this Builder

setLaunchSingleTop

public NavOptions.Builder setLaunchSingleTop (boolean singleTop)

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

Returns
NavOptions.Builder

setPopEnterAnim

public NavOptions.Builder setPopEnterAnim (int popEnterAnim)

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 int: Custom animation to run

Returns
NavOptions.Builder this Builder

setPopExitAnim

public NavOptions.Builder setPopExitAnim (int popExitAnim)

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 int: Custom animation to run

Returns
NavOptions.Builder this Builder

setPopUpTo

public NavOptions.Builder setPopUpTo (int destinationId, 
                boolean inclusive)

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 int: The destination to pop up to, clearing all intervening destinations.

inclusive boolean: true to also pop the given destination from the back stack.

Returns
NavOptions.Builder this Builder