T - The type of parsed response this future expects.public class RequestFuture<T> extends Object implements Future<T>, Response.Listener<T>, Response.ErrorListener
RequestFuture<JSONObject> future = RequestFuture.newFuture();
MyRequest request = new MyRequest(URL, future, future);
// If you want to be able to cancel the request:
future.setRequest(requestQueue.add(request));
// Otherwise:
requestQueue.add(request);
try {
JSONObject response = future.get();
// do something with response
} catch (InterruptedException e) {
// handle the error
} catch (ExecutionException e) {
// handle the error
}
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
T |
get() |
T |
get(long timeout,
TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
static <E> RequestFuture<E> |
newFuture() |
void |
onErrorResponse(VolleyError error)
Callback method that an error has been occurred with the
provided error code and optional user-readable message.
|
void |
onResponse(T response)
Called when a response is received.
|
void |
setRequest(Request<?> request) |
public static <E> RequestFuture<E> newFuture()
public void setRequest(Request<?> request)
public boolean cancel(boolean mayInterruptIfRunning)
public T get() throws InterruptedException, ExecutionException
get in interface Future<T>InterruptedExceptionExecutionExceptionpublic T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface Future<T>InterruptedExceptionExecutionExceptionTimeoutExceptionpublic boolean isCancelled()
isCancelled in interface Future<T>public void onResponse(T response)
Response.ListeneronResponse in interface Response.Listener<T>public void onErrorResponse(VolleyError error)
Response.ErrorListeneronErrorResponse in interface Response.ErrorListenerCopyright © 2015. All rights reserved.