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)

This method is deprecated. Use setPopUpTo(int, boolean) with the id of the NavController's graph and set inclusive to true.

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)

This method is deprecated. As per the Intent.FLAG_ACTIVITY_NEW_DOCUMENT documentation, it is recommended to use R.attr.documentLaunchMode on an Activity you wish to launch as a new document.

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

public NavOptions.Builder ()

Public methods

build

public NavOptions build ()

Returns
NavOptions a constructed NavOptions

setClearTask

public NavOptions.Builder setClearTask (boolean clearTask)

This method is deprecated.
Use setPopUpTo(int, boolean) with the id of the NavController's graph and set inclusive to true.

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

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

setLaunchDocument

public NavOptions.Builder setLaunchDocument (boolean launchDocument)

This method is deprecated.
As per the Intent.FLAG_ACTIVITY_NEW_DOCUMENT documentation, it is recommended to use R.attr.documentLaunchMode on an Activity you wish to launch as a new document.

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

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