安卓:在AsyncTask的HTTP请求不并发 [英] Android: HTTP requests in AsyncTask are not concurrent

查看:152
本文介绍了安卓:在AsyncTask的HTTP请求不并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的我的本地电影中心风扇的应用程序< /一>,这表明筛选日历接下来的几天。每天的膜列表是使用一<一个检索href="http://www.sderot-cin.org.il/cgi-webaxy/sal/sal.pl?ID=839468_cinematheque&act=search2&dbResOptions=hideResTabTitle=0&getValueAJAX=dataid,f1,f2,f3,f4&dbid=shows2009&query=sort%3CD%3Ef3%3CD%3Esort2%3CD%3Ef4%3CD%3Ef2%3CD%3E8/11/2012%3CD%3Ef2%3CD%3E8/11/2012"相对=nofollow>参数化HTTP从网站调用(答案包含希伯来文,所以如果你点击了链接,并得到了一些废话它可能确定)。

I'm writing a fan app for my local cinematheque, which shows the screening calendar for the next few days. The per-day film list is retrieved using a parametrized HTTP call from the site (The answer contains Hebrew, so if you clicked the link and got some Gibberish it's probably OK).

该应用程序会显示在接下来的八天的时间表,所以它使8通话每一天的时间表要求。

The app displays the schedule for the next eight days, so It makes 8 calls with per-day schedule request.

private class GetMoviesTask extends AsyncTask<Integer, Void, List<Film>>

doInBackground()检索每天的电影名单,而 onPostExecute()更新的接口。

doInBackground() retrieves the list of films per day, and onPostExecute() updates the interface.

该AsyncTask的是从 MainActivity.onCreate称为()

The AsyncTask is called from MainActivity.onCreate():

for (int i=0; i<NUMBER_OF_DAYS_TO_VIEW; i++){
    new GetMoviesTask().execute(i);
}

的问题是,AsyncTask的不同时执行。日子正在慢慢装了一个又一个,这是痛苦的缓慢:

The problem is that AsyncTask is not executed concurrently. The days are slowly loaded one after another, which is painfully slow:

什么是同时启动这些AsyncCalls的最佳方法是什么?

What's the best way to start these AsyncCalls concurrently?

推荐答案

的AsyncTask 已经知道打了一个回归的安卓4.x中,在系统执行它们一次的,而不是执行它们兼任它,因为Android 1.6的一样。这是由设计:基本上,在新平台上,你可以通过调用恢复为原来的并发行为 executeOnExecutor()而不是执行()。马克·墨菲(被称为 Commonsware 的计算器)具有的all细节进行排序在他的博客。

AsyncTask has been known to hit a regression in Android 4.x, where the system executes them one at a time instead of executing them concurrently as it did since Android 1.6. This is by design: basically, on newer platforms, you can revert to the old concurrent behaviour by calling executeOnExecutor() instead of execute(). Mark Murphy (known as Commonsware on StackOverflow) has all the details sorted on his blog.

这篇关于安卓:在AsyncTask的HTTP请求不并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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