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

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. detail pages about similar data items) that should not preserve history.

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
<T extends Object> setPopUpTo(boolean inclusive, boolean saveState)

Pop up to a given destination before navigating.

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

Pop up to a given destination before navigating.

final @NonNull NavOptions.Builder
<T extends Object> setPopUpTo(
    @NonNull T route,
    boolean inclusive,
    boolean saveState
)

Pop up to a given destination before navigating.

final @NonNull NavOptions.Builder
setPopUpTo(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

Added in 1.0.0
public Builder()

Public methods

build

Added in 1.0.0
public final @NonNull NavOptions build()
Returns
@NonNull NavOptions

a constructed NavOptions

setEnterAnim

Added in 1.0.0
public final @NonNull 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
@NonNull NavOptions.Builder

this Builder

See also
enterAnim

setExitAnim

Added in 1.0.0
public final @NonNull 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
@NonNull NavOptions.Builder

this Builder

See also
exitAnim

setLaunchSingleTop

Added in 1.0.0
public 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. detail pages about similar data items) that should not preserve history.

Parameters
boolean singleTop

true to launch as single-top

setPopEnterAnim

Added in 1.0.0
public 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.

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

Parameters
@AnimRes @AnimatorRes int popEnterAnim

Custom animation to run

Returns
@NonNull NavOptions.Builder

this Builder

See also
popEnterAnim

setPopExitAnim

Added in 1.0.0
public 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.

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

Parameters
@AnimRes @AnimatorRes int popExitAnim

Custom animation to run

Returns
@NonNull NavOptions.Builder

this Builder

See also
popExitAnim

setPopUpTo

public final @NonNull NavOptions.Builder <T extends Object> setPopUpTo(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
<T extends Object>

route from a KClass 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 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
@NonNull NavOptions.Builder

this Builder

setPopUpTo

Added in 2.4.0
public final @NonNull 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
@NonNull NavOptions.Builder

this Builder

setPopUpTo

Added in 2.8.0
public final @NonNull NavOptions.Builder <T extends Object> setPopUpTo(
    @NonNull T 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
@NonNull T route

route from an Object 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 route from an Object as popUpToRouteObject (note: this matching route is true whether inclusive is true or false).

Returns
@NonNull NavOptions.Builder

this Builder

setPopUpTo

Added in 2.4.0
public final @NonNull NavOptions.Builder setPopUpTo(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
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
@NonNull NavOptions.Builder

this Builder

setRestoreState

Added in 2.4.0
public final @NonNull 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.