NavOptions.Builder

public final class NavOptions.Builder


Builder for constructing new instances of NavOptions.

Summary

Public constructors

Public methods

final @NonNull NavOptions
final @NonNull NavOptions.Builder
setEnterAnim(@AnimRes @AnimatorRes int enterAnim)

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

final @NonNull NavOptions.Builder
setExitAnim(@AnimRes @AnimatorRes int exitAnim)

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

final @NonNull 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.

final @NonNull NavOptions.Builder
setPopEnterAnim(@AnimRes @AnimatorRes int popEnterAnim)

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

final @NonNull NavOptions.Builder
setPopExitAnim(@AnimRes @AnimatorRes int popExitAnim)

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

final @NonNull NavOptions.Builder
setPopUpTo(@IdRes int destinationId, boolean inclusive, boolean saveState)

Pop up to a given destination before navigating.

final @NonNull NavOptions.Builder
setPopUpTo(@Nullable String route, boolean inclusive, boolean saveState)

Pop up to a given destination before navigating.

final @NonNull NavOptions.Builder
setRestoreState(boolean restoreState)

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

Public constructors

Builder

@NonNull
public final Builder()

Public methods

build

@NonNull
public final NavOptions build()
Returns
NavOptions

a constructed NavOptions

setEnterAnim

@NonNull
public final NavOptions.Builder setEnterAnim(@AnimRes @AnimatorRes 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
@AnimRes @AnimatorRes int enterAnim

Custom animation to run

Returns
NavOptions.Builder

this Builder

See also
enterAnim

setExitAnim

@NonNull
public final NavOptions.Builder setExitAnim(@AnimRes @AnimatorRes 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
@AnimRes @AnimatorRes int exitAnim

Custom animation to run

Returns
NavOptions.Builder

this Builder

See also
exitAnim

setLaunchSingleTop

@NonNull
public final 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
boolean singleTop

true to launch as single-top

setPopEnterAnim

@NonNull
public final NavOptions.Builder setPopEnterAnim(@AnimRes @AnimatorRes 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
@AnimRes @AnimatorRes int popEnterAnim

Custom animation to run

Returns
NavOptions.Builder

this Builder

See also
popEnterAnim

setPopExitAnim

@NonNull
public final NavOptions.Builder setPopExitAnim(@AnimRes @AnimatorRes 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
@AnimRes @AnimatorRes int popExitAnim

Custom animation to run

Returns
NavOptions.Builder

this Builder

See also
popExitAnim

setPopUpTo

@NonNull
public final NavOptions.Builder setPopUpTo(@IdRes int destinationId, boolean inclusive, boolean saveState)

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

Parameters
@IdRes int destinationId

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

boolean inclusive

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

boolean saveState

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

@NonNull
public final NavOptions.Builder setPopUpTo(@Nullable String route, boolean inclusive, boolean saveState)

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

Parameters
@Nullable String route

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

boolean inclusive

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

boolean saveState

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

@NonNull
public final NavOptions.Builder setRestoreState(boolean restoreState)

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.