NavOptions.Builder

public static 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 setClearTask(boolean clearTask)

Clear the entire task before launching this target.

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 setLaunchDocument(boolean launchDocument)

Launch a navigation target as a document if you want it to appear as its own entry in the system Overview screen.

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

NavOptions.Builder

NavOptions.Builder ()

Public methods

build

NavOptions build ()

Returns
NavOptions a constructed NavOptions

setClearTask

NavOptions.Builder setClearTask (boolean clearTask)

Clear the entire task before launching this target. If you are launching as a document, this will clear the document task. Otherwise it will clear the current task.

Returns
NavOptions.Builder

setEnterAnim

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

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

setLaunchDocument

NavOptions.Builder setLaunchDocument (boolean launchDocument)

Launch a navigation target as a document if you want it to appear as its own entry in the system Overview screen. If the same document is launched multiple times it will not create a new task, it will bring the existing document task to the front.

If the user presses the system Back key from a new document task they will land on their previous task. If the user reached the document task from the system Overview screen they will be taken to their home screen.

Parameters
launchDocument boolean: true to launch a new document task

Returns
NavOptions.Builder

setLaunchSingleTop

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

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

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

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