Batch

public final class Batch extends PendingResult


Handles a batch of PendingResult items. Callbacks can be added and you can block to wait for all items in the batch to complete like any other PendingResult item. A Batch can also be canceled if the results are no longer needed. In this case, the onBatchComplete callback will never be triggered.

The results can be taken either from the underlying PendingResults or via take but not both.

Summary

Nested types

public final class Batch.Builder

Builder for Batch objects.

Protected fields

final WeakReference<GoogleApiClient>

This reference will never be null so long as the GoogleApiClient is connected.

Public methods

final R

Blocks until the task is completed.

final R
await(long time, TimeUnit units)

Blocks until the task is completed or has timed out waiting for the result.

void

Requests that the batch be canceled.

void
boolean

Indicates whether the pending result has been canceled either due to calling disconnect or calling cancel directly on the pending result or an enclosing Batch.

final void

Set the callback here if you want the result to be delivered via a callback when the result is ready.

final void
setResultCallback(
    ResultCallback<Object> callback,
    long time,
    TimeUnit units
)

Set the callback here if you want the result to be delivered via a callback when the result is ready or has timed out waiting for the result.

Inherited methods

From com.google.android.gms.common.api.PendingResult
abstract @NonNull R
await(long time, @NonNull TimeUnit units)

Blocks until the task is completed or has timed out waiting for the result.

abstract void

Set the callback here if you want the result to be delivered via a callback when the result is ready.

abstract void
setResultCallback(
    @NonNull ResultCallback<Object> callback,
    long time,
    @NonNull TimeUnit units
)

Set the callback here if you want the result to be delivered via a callback when the result is ready or has timed out waiting for the result.

@NonNull TransformedResult<S>
<S extends Result> then(@NonNull ResultTransform<Object, S> transform)

Transforms the result by making another API call.

Protected fields

mApiClient

protected final WeakReference<GoogleApiClientmApiClient

This reference will never be null so long as the GoogleApiClient is connected. It needs to be weak so that PendingResults don't pin disconnected GACs due to binder references to the PendingResults.

Public methods

await

public final R await()

Blocks until the task is completed. This is not allowed on the UI thread. The returned result object can have an additional failure mode of INTERRUPTED.

await

public final R await(long time, TimeUnit units)

Blocks until the task is completed or has timed out waiting for the result. This is not allowed on the UI thread. The returned result object can have an additional failure mode of either INTERRUPTED or TIMEOUT.

cancel

public void cancel()

Requests that the batch be canceled. Cancels all underlying PendingResults.

onResult will never be called, await will return a failed result with status CANCELED.

clearResultCallback

public void clearResultCallback()

isCanceled

public boolean isCanceled()

Indicates whether the pending result has been canceled either due to calling disconnect or calling cancel directly on the pending result or an enclosing Batch.

setResultCallback

public final void setResultCallback(@Nullable ResultCallback<Object> callback)

Set the callback here if you want the result to be delivered via a callback when the result is ready.

setResultCallback

public final void setResultCallback(
    ResultCallback<Object> callback,
    long time,
    TimeUnit units
)

Set the callback here if you want the result to be delivered via a callback when the result is ready or has timed out waiting for the result. The returned result object can have an additional failure mode of TIMEOUT.