T
- The type of parsed response this future expects.public class RequestFuture<T> extends java.lang.Object implements java.util.concurrent.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,
java.util.concurrent.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)
cancel
in interface java.util.concurrent.Future<T>
public T get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<T>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public T get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
get
in interface java.util.concurrent.Future<T>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
public boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<T>
public boolean isDone()
isDone
in interface java.util.concurrent.Future<T>
public void onResponse(T response)
Response.Listener
onResponse
in interface Response.Listener<T>
public void onErrorResponse(VolleyError error)
Response.ErrorListener
onErrorResponse
in interface Response.ErrorListener