应用程序不能在ICS版本由于NetworkOnMainThreadException工作正常 [英] App not working fine on ICS version due to NetworkOnMainThreadException

查看:145
本文介绍了应用程序不能在ICS版本由于NetworkOnMainThreadException工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个Android应用程序,将去住几日。

I have developed an Android App which will go live in few days.

测试上ICS应用程序时,我所遇到的不同的问题。
它正在pre-姜饼和姜饼版本设备的罚款。它扔 NetworkOnMainThreadException 测试时ICS的设备和管理,通过把HTTP调用的AsyncTask 来删除。

I have come across a different problem when testing the app on ICS. It is working fine on Pre-GingerBread and GingerBread version devices. It is throwing NetworkOnMainThreadException when tested ICS device and managed to remove that by putting HTTP Calls in AsyncTask.

但我的问题是我提出4至5个不同的 HTTP URL调用并调用每个URL需要的AsyncTask因为这些URL应该同时执行另一个之后。

But my issue is I am making 4 to 5 different HTTP Url calls and calling every url require a AsyncTask as these URLs should execute concurrently one after other.

如果一个网址,结果失败下一个不应该被调用,并且应该更新UI。所以我采取一种的AsyncTask 每个URL呼叫。

If result of one url is failed next one should not be called and that should updated on UI. So I am taking an AsyncTask for each URL Call.

我们能否有许多 AsyncTasks 在单一片段或没有。由于我好不容易才具有最大的3 的AsyncTask 在我的片段类。

Can we have many AsyncTasks in a Single Fragment or not. As of I Managed to have Maximum 3 AsyncTask in my Fragment Class.

如果这样,我们才能开始执行另一个的AsyncTask 从第一个的AsyncTask PostExecute 方法。

If so can we start executing another AsyncTask from first AsyncTask PostExecute method.

先谢谢了。

推荐答案

您可以把所有的HTTP调用一个的AsyncTask 并报告与<一个href=\"http://developer.android.com/reference/android/os/AsyncTask.html#publishProgress%28Progress...%29\"相对=nofollow> publishProgress 回调。当一个人失败了,你可以停止的AsyncTask和其他人将不会被调用。

You can put all the HTTP calls in one ASyncTask and report back with the publishProgress callback. When one fails, you can stop that ASyncTask and the others won't be called.

这篇关于应用程序不能在ICS版本由于NetworkOnMainThreadException工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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