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

Pop up to a given destination before navigating.

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

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

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 ID is true if inclusive is true. If inclusive is false, this matching ID is the id of the last destination that is popped).

Returns
@NonNull NavOptions.Builder

this Builder

setPopUpTo

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

from the KClass of the destination T 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 ID is true if inclusive is true. If inclusive is false, this matching ID is the id of the last destination that is popped).

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 ID is true if inclusive is true. If inclusive is false, this matching ID is the id of the last destination that is popped).

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 if inclusive is true. If inclusive is false, this matching ID is the id of the last destination that is popped).

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.