RetryPolicy.Builder


@ExperimentalRetryPolicy
public final class RetryPolicy.Builder


A builder class for customizing RetryPolicy behavior.

Use the Builder to modify existing RetryPolicy instances, typically starting with the predefined options like DEFAULT or RETRY_UNAVAILABLE_CAMERA. The most common use is to set a custom timeout.

Example: Create a policy based on DEFAULT with a 10-second timeout:

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

Summary

Public constructors

Creates a builder based on an existing RetryPolicy.

Public methods

@NonNull RetryPolicy

Creates the customized RetryPolicy instance.

@NonNull RetryPolicy.Builder
setTimeoutInMillis(long timeoutInMillis)

Sets a timeout in milliseconds.

Public constructors

Builder

Added in 1.4.0
public Builder(@NonNull RetryPolicy basePolicy)

Creates a builder based on an existing 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
@NonNull RetryPolicy basePolicy

The RetryPolicy to use as a starting point.

Public methods

build

Added in 1.4.0
public @NonNull RetryPolicy build()

Creates the customized RetryPolicy instance.

Returns
@NonNull RetryPolicy

The new RetryPolicy.

setTimeoutInMillis

Added in 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 NOT_RETRY.

Parameters
long timeoutInMillis

The maximum duration for retries in milliseconds. A value of 0 indicates no timeout.

Returns
@NonNull RetryPolicy.Builder

this for method chaining.