Batch | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Nested Classes | Methods | Inherited Methods | [Expand All]
public final class

# Batch

extends Object
implements PendingResult<R extends Result>

java.lang.Object
↳ | com.google.android.gms.common.api.Batch

## Class Overview

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 `PendingResult`s or via `take(BatchResultToken)` but not both.

## Summary

Nested Classes
class | Batch.Builder | Builder for `Batch` objects.

Public Methods
final R extends Result | await() Blocks until the task is completed.
final R extends Result | await(long time, TimeUnit units) Blocks until the task is completed or has timed out waiting for the result.
void | cancel() Requests that the batch be canceled.
BatchResult | createFailedResult(Status status) Creates a result of type `` that represents a failure with the specified `Status`.
boolean | isCanceled() Indicates whether the pending result has been canceled either due to calling {GoogleApiClient#disconnect} or calling `cancel()` directly on the pending result or an enclosing `Batch`.
final boolean | isReady()
final void | setResultCallback(ResultCallback<R extends Result> 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.
final void | setResultCallback(ResultCallback<R extends Result> callback) Set the callback here if you want the result to be delivered via a callback when the result is ready.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
From interface com.google.android.gms.common.api.PendingResult
abstract R | await() Blocks until the task is completed.
abstract R | await(long time, TimeUnit units) Blocks until the task is completed or has timed out waiting for the result.
abstract void | cancel() Requests that the PendingResult be canceled.
abstract boolean | isCanceled() Indicates whether the pending result has been canceled either due to calling {GoogleApiClient#disconnect} or calling `cancel()` directly on the pending result or an enclosing `Batch`.
abstract void | setResultCallback(ResultCallback<R> 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.
abstract void | setResultCallback(ResultCallback<R> callback) Set the callback here if you want the result to be delivered via a callback when the result is ready.

## Public Methods

#### public final R extends Result 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`.

#### public final R extends Result 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`.

#### public void cancel ()

Requests that the batch be canceled. Cancels all underlying `PendingResult`s.

`onResult(Result)` will never be called, `await()` will return a failed result with status `CANCELED`.

#### public BatchResult createFailedResult (Status status)

Creates a result of type `` that represents a failure with the specified `Status`.

#### public boolean isCanceled ()

Indicates whether the pending result has been canceled either due to calling {GoogleApiClient#disconnect} or calling `cancel()` directly on the pending result or an enclosing `Batch`.

#### public final boolean isReady ()

#### public final void setResultCallback (ResultCallback<R extends Result> 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`.

#### public final void setResultCallback (ResultCallback<R extends Result> callback)

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