取消AsyncTask的挂起新的Htt prequests [英] Cancelled AsyncTask hangs new HttpRequests

查看:127
本文介绍了取消AsyncTask的挂起新的Htt prequests的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与asynctasks和HTTP请求的问题。

I'm having problem with asynctasks and http requests.

用户可以preSS两个不同的按钮。两个按钮从Web服务器下载信息。我想请求被取消。每前调用progressdialog所示。

The user can press two different buttons. Both buttons download information from a web server. I want the requests to be cancelable. Before each call a progressdialog is shown.

HTTP请求是在执行的AsyncTask,我有上取消的AsyncTask的progressdialog的OnDismiss听众,如果后面是pressed。

The http request is performed in an asynctask, and I have an OnDismiss listener on the progressdialog that cancels the asynctask if back is pressed.

它的工作原理50/50。

It works 50/50.

如果我做的http请求,取消AsyncTask的,然后做一个新的请求,它可能会工作,但它也可能导致HTTP请求挂起无限。

If I do the http request, cancel the asynctask, then do a new request, it might work but it might also cause the http request to hang infinite.

这行是它挂起:

=响应httpclient.execute(URLConnection的,上下文);

有没有其他办法可以做到一个电话是取消还是有什么我可以做些什么来避免挂?

Is there any other way to do a call that is cancelable or is there anything I could do to avoid the hang?

推荐答案

我写了的AsyncTask 执行通过HTTP下载一些资料,我发现,调用取消()的任务实际上并没有从执行停止任务。 已取消的任务将继续执行其后台操作。调用取消()似乎只是叫 onCancelled(),然后的AsyncTask 的通话 onPostExecute()时,它已经完成了。也许你的第一项任务仍然有下一个任务需要一定的网络资源?

I wrote an AsyncTask to perform some downloads over http, and I found that calling cancel() on the task doesn't actually stop the task from executing. The "cancelled" task will continue to perform its background actions. Calling cancel() just seemed to call onCancelled() and then the AsyncTask doesn't call onPostExecute() when it has finished. Perhaps your first task still has hold of some network resource that the next task requires?

这篇关于取消AsyncTask的挂起新的Htt prequests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆