use of com.loopj.android.http.RequestHandle in project android-async-http by loopj.
the class AsyncBackgroundThreadSample method executeSample.
@Override
public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) {
final Activity ctx = this;
FutureTask<RequestHandle> future = new FutureTask<>(new Callable<RequestHandle>() {
public RequestHandle call() {
Log.d(LOG_TAG, "Executing GET request on background thread");
return client.get(ctx, URL, headers, null, responseHandler);
}
});
executor.execute(future);
RequestHandle handle = null;
try {
handle = future.get(5, TimeUnit.SECONDS);
Log.d(LOG_TAG, "Background thread for GET request has finished");
} catch (Exception e) {
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return handle;
}
use of com.loopj.android.http.RequestHandle in project android-async-http by loopj.
the class CancelRequestHandleSample method onCancelButtonPressed.
@Override
public void onCancelButtonPressed() {
Log.d(LOG_TAG, String.format("Number of handles found: %d", getRequestHandles().size()));
int counter = 0;
for (RequestHandle handle : getRequestHandles()) {
if (!handle.isCancelled() && !handle.isFinished()) {
Log.d(LOG_TAG, String.format("Cancelling handle %d", counter));
Log.d(LOG_TAG, String.format("Handle %d cancel", counter) + (handle.cancel(true) ? " succeeded" : " failed"));
} else {
Log.d(LOG_TAG, String.format("Handle %d already non-cancellable", counter));
}
counter++;
}
}
Aggregations