FileAsyncHttpResponseHandler取消请求

时间:2015-07-16 20:22:56

标签: android request androidhttpclient android-async-http

我想在Android应用中取消FileAsyncHttpResponseHandler请求,但只有一个(不是全部)。有这些方法可用,但它们都没有取消请求。它一直持续到文件完全下载为止。

FileAsyncHttpResponseHandler fileAsyncHttpResponseHandler;
...get request...
fileAsyncHttpResponseHandler.deleteTargetFile();
fileAsyncHttpResponseHandler.onCancel();
fileAsyncHttpResponseHandler.sendCancelMessage();

请帮助我!!

1 个答案:

答案 0 :(得分:2)

我是所说的图书馆,你基本上有三种选择。

首先,从创建请求中获取AsyncHttpClient ahc = new AsyncHttpClient(); RequestHandle rh = ahc.get(context, url, fileResponseHandler); rh.cancel(); ,然后通过

取消
AsyncHttpClient ahc = new AsyncHttpClient();
ahc.get(CurrentActivity.this, url, fileResponseHandler);
ahc.cancelRequests(CurrentActivity.this, boolean mayInterruptIfRunning);

其次,通过归属上下文取消请求

getTag()

第三,目前处于1.4.8快照(可能会在星期日发布1.4.8发布),在请求中放置一个TAG(或在ResponseHandler中实现String myTag = "my-long-identifier-such-as-uuid"; AsyncHttpClient ahc = new AsyncHttpClient(); RequestHandle rh = ahc.get(context, url, fileResponseHandler); rh.setTag(myTag); ahc.cancelRequestsByTAG(myTag, boolean mayInterruptIfRunning); ,并通过所述TAG取消)

AsyncHttpClient ahc = new AsyncHttpClient();
ahc.get(context, url, new FileAsyncHttpResponseHandler(){
    // implement all methods
    // override getTag() to identify request associated with this responseHandler
    // for example return "url" for ability to cancel by request URL
    @Override
    public Object getTag() { return url; }
});
ahc.cancelRequestsByTAG(url, boolean mayInterruptIfRunning);

或通过从响应处理程序

实现getTag()
L.Routing.control({ createMarker: function() { return null; } });
相关问题