# NavOptionsBuilder

Artifact: [androidx.navigation:navigation-common](https://developer.android.com/jetpack/androidx/releases/navigation) [View Source](https://cs.android.com/search?q=file:androidx/navigation/NavOptionsBuilder.+class:androidx.navigation.NavOptionsBuilder) Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

*** ** * ** ***


```
@NavOptionsDsl
public final class NavOptionsBuilder
```

<br />

*** ** * ** ***

DSL for constructing a new `https://developer.android.com/reference/androidx/navigation/NavOptions`

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#NavOptionsBuilder()()` |

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#anim(kotlin.Function1)(@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/AnimBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> animBuilder)` Sets any custom Animation or Animator resources that should be used. |
| `final boolean` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#getLaunchSingleTop()()` Whether this navigation action should launch as single-top (i.e., there will be at most one copy of a given destination on the top of the back stack). |
| `final int` | `[getPopUpTo](https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#getPopUpTo())()` **This method is deprecated.** Use the popUpToId property. |
| `final int` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#getPopUpToId()()` Returns the current destination that the builder will pop up to. |
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#getPopUpToRoute()()` The destination to pop up to before navigating. |
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#getPopUpToRouteClass()()` The destination to pop up to before navigating. |
| `final https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#getPopUpToRouteObject()()` The destination to pop up to before navigating. |
| `final boolean` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#getRestoreState()()` Whether this navigation action should restore any state previously saved by `https://developer.android.com/reference/androidx/navigation/PopUpToBuilder#saveState()` or the `popUpToSaveState` attribute. |
| `final void` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#popUpTo(kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder )` Pop up to a given destination before navigating. |
| `final void` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#popUpTo(kotlin.Int,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/IdRes int id, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder )` Pop up to a given destination before navigating. |
| `final void` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#popUpTo(kotlin.reflect.KClass,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> route, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder )` Pop up to a given destination before navigating. |
| `final void` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#popUpTo(kotlin.Any,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull T route, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder )` Pop up to a given destination before navigating. |
| `final void` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#popUpTo(kotlin.String,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html route, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder )` Pop up to a given destination before navigating. |
| `final void` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#setLaunchSingleTop(kotlin.Boolean)(boolean value)` Whether this navigation action should launch as single-top (i.e., there will be at most one copy of a given destination on the top of the back stack). |
| `final void` | `[setPopUpTo](https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#setPopUpTo(kotlin.Int))(int value)` **This method is deprecated.** Use the popUpTo function and passing in the id. |
| `final void` | `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#setRestoreState(kotlin.Boolean)(boolean value)` Whether this navigation action should restore any state previously saved by `https://developer.android.com/reference/androidx/navigation/PopUpToBuilder#saveState()` or the `popUpToSaveState` attribute. |

## Public constructors

### NavOptionsBuilder

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public NavOptionsBuilder()
```

## Public methods

### anim

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final void anim(@NonNull Function1<@NonNull AnimBuilder, Unit> animBuilder)
```

Sets any custom Animation or Animator resources that should be used.

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

### getLaunchSingleTop

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final boolean getLaunchSingleTop()
```

Whether this navigation action should launch as single-top (i.e., there will be at most one copy of a given destination on the top of the back stack).

This functions similarly to how [android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP](https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_SINGLE_TOP) works with activities.

### getPopUpTo

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0) Deprecated in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final int [getPopUpTo](https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#getPopUpTo())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Use the popUpToId property.

The destination to pop up to before navigating. All non-matching destinations from the back stack up until this destination will also be popped.

### getPopUpToId

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final int getPopUpToId()
```

Returns the current destination that the builder will pop up to.

### getPopUpToRoute

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final String getPopUpToRoute()
```

The destination to pop up to before navigating. All non-matching destinations from the back stack up until this destination will also be popped.

### getPopUpToRouteClass

Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.8.0)

```
public final KClass<@NonNull ?> getPopUpToRouteClass()
```

The destination to pop up to before navigating. All non-matching destinations from the back stack up until this destination will also be popped.

### getPopUpToRouteObject

Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.8.0)

```
public final Object getPopUpToRouteObject()
```

The destination to pop up to before navigating. All non-matching destinations from the back stack up until this destination will also be popped.

### getRestoreState

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final boolean getRestoreState()
```

Whether this navigation action should restore any state previously saved by `https://developer.android.com/reference/androidx/navigation/PopUpToBuilder#saveState()` or the `popUpToSaveState` attribute. If no state was previously saved with the destination ID being navigated to, this has no effect.

### popUpTo

```
public final void <T extends Object> popUpTo(
    @NonNull Function1<@NonNull PopUpToBuilder, Unit> popUpToBuilder
)
```

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

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html>` | route from a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html` for the destination |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder` | builder used to construct a popUpTo operation |

### popUpTo

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final void popUpTo(
    @IdRes int id,
    @NonNull Function1<@NonNull PopUpToBuilder, Unit> popUpToBuilder
)
```

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

### popUpTo

Added in [2.9.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.9.0)

```
public final void <T extends Object> popUpTo(
    @NonNull KClass<@NonNull T> route,
    @NonNull Function1<@NonNull PopUpToBuilder, Unit> popUpToBuilder
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> route` | the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html` of the destination `https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#popUpTo(kotlin.reflect.KClass,kotlin.Function1)` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder` | builder used to construct a popUpTo operation |

### popUpTo

Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.8.0)

```
public final void <T extends Object> popUpTo(
    @NonNull T route,
    @NonNull Function1<@NonNull PopUpToBuilder, Unit> popUpToBuilder
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T route` | route from a Object for the destination |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder` | builder used to construct a popUpTo operation |

### popUpTo

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final void popUpTo(
    @NonNull String route,
    @NonNull Function1<@NonNull PopUpToBuilder, Unit> popUpToBuilder
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html route` | route for the destination |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/PopUpToBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> popUpToBuilder` | builder used to construct a popUpTo operation |

### setLaunchSingleTop

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final void setLaunchSingleTop(boolean value)
```

Whether this navigation action should launch as single-top (i.e., there will be at most one copy of a given destination on the top of the back stack).

This functions similarly to how [android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP](https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_SINGLE_TOP) works with activities.

### setPopUpTo

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0) Deprecated in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final void [setPopUpTo](https://developer.android.com/reference/androidx/navigation/NavOptionsBuilder#setPopUpTo(kotlin.Int))(int value)
```

> [!CAUTION]
> **This method is deprecated.**   
> Use the popUpTo function and passing in the id.

The destination to pop up to before navigating. All non-matching destinations from the back stack up until this destination will also be popped.

### setRestoreState

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public final void setRestoreState(boolean value)
```

Whether this navigation action should restore any state previously saved by `https://developer.android.com/reference/androidx/navigation/PopUpToBuilder#saveState()` or the `popUpToSaveState` attribute. If no state was previously saved with the destination ID being navigated to, this has no effect.