# RetryPolicy.Builder

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/RetryPolicy.java+class:androidx.camera.core.RetryPolicy.Builder) Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/camera#1.4.0)

*** ** * ** ***


```
@ExperimentalRetryPolicy
public final class RetryPolicy.Builder
```

<br />

*** ** * ** ***

A builder class for customizing RetryPolicy behavior.

Use the `https://developer.android.com/reference/androidx/camera/core/RetryPolicy.Builder#Builder(androidx.camera.core.RetryPolicy)` to modify existing RetryPolicy instances, typically starting with the predefined options like `https://developer.android.com/reference/androidx/camera/core/RetryPolicy#DEFAULT()` or `https://developer.android.com/reference/androidx/camera/core/RetryPolicy#RETRY_UNAVAILABLE_CAMERA()`. The most common use is to set a custom timeout.

Example: Create a policy based on `https://developer.android.com/reference/androidx/camera/core/RetryPolicy#DEFAULT()` with a 10-second timeout:

```
new RetryPolicy.Builder(RetryPolicy.DEFAULT).setTimeoutInMillis(10000L).build()
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/core/RetryPolicy.Builder#Builder(androidx.camera.core.RetryPolicy)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/RetryPolicy basePolicy)` Creates a builder based on an existing `https://developer.android.com/reference/androidx/camera/core/RetryPolicy`. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/RetryPolicy` | `https://developer.android.com/reference/androidx/camera/core/RetryPolicy.Builder#build()()` Creates the customized `https://developer.android.com/reference/androidx/camera/core/RetryPolicy` instance. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/RetryPolicy.Builder` | `https://developer.android.com/reference/androidx/camera/core/RetryPolicy.Builder#setTimeoutInMillis(long)(long timeoutInMillis)` Sets a timeout in milliseconds. |

## Public constructors

### Builder

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

```
public Builder(@NonNull RetryPolicy basePolicy)
```

Creates a builder based on an existing `https://developer.android.com/reference/androidx/camera/core/RetryPolicy`.

This allows you to start with a predefined policy and add further customizations. For example, set a timeout to prevent retries from continuing endlessly.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/RetryPolicy basePolicy` | The RetryPolicy to use as a starting point. |

## Public methods

### build

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

```
public @NonNull RetryPolicy build()
```

Creates the customized `https://developer.android.com/reference/androidx/camera/core/RetryPolicy` instance.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/RetryPolicy` | The new `https://developer.android.com/reference/androidx/camera/core/RetryPolicy`. |

### setTimeoutInMillis

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

```
public @NonNull RetryPolicy.Builder setTimeoutInMillis(long timeoutInMillis)
```

Sets a timeout in milliseconds. If retries exceed this duration, they will be terminated with `https://developer.android.com/reference/androidx/camera/core/RetryPolicy.RetryConfig#NOT_RETRY()`.

| Parameters |
|---|---|
| `long timeoutInMillis` | The maximum duration for retries in milliseconds. A value of 0 indicates no timeout. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/RetryPolicy.Builder` | `this` for method chaining. |