HonyComb和DefaultHttpClient [英] HonyComb and DefaultHttpClient

查看:287
本文介绍了HonyComb和DefaultHttpClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的code我有这样的

In my code I have this

        Log.d("WFlog (executeRequest)", request.toString()) ;
        httpResponse = client.execute(request);  
        Log.d("WFlog (execute)", request.toString()) ;

运行采用Android 2.2的应用程序会很好,在我的logcat看到两个日志行。

running the app using Android 2.2 is going fine and in logcat I see both log lines.

现在使用HonyComb为同一块$ C $了C好像我从来没有得到正确的通过client.execute运行的应用程序。我得到的最后一个日志行是一个具有WFlog(executeRequest)。

Now running the app using HonyComb for the same piece of code it seems I never get passed the client.execute correctly. The last log line I get is the one having "WFlog (executeRequest)".

在此我看到以下内容:

01-27 21:54:45.169: WARN/System.err(390): android.os.NetworkOnMainThreadException
01-27 21:54:45.196: WARN/System.err(390):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1069)
01-27 21:54:45.196: WARN/System.err(390):     at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:368)
01-27 21:54:45.205: WARN/System.err(390):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)
01-27 21:54:45.215: WARN/System.err(390):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)
01-27 21:54:45.237: WARN/System.err(390):     at java.net.Socket.connect(Socket.java:901)

任何想法,我应该找什么?

Any idea what I should look for?

推荐答案

有新的政策,允许应用程序和操作系统开发者设定的业绩预期为code上执行某些线程。你试图调用阻塞网络API的应用程序的UI线程。谷歌已经建立了一个系统,让你知道这是一个坏主意,你可以通过执行您的要求在一个单独的线程或AsyncTask的解决这个问题。

There are new policies that allow application and operating system developers to set performance expectations for code executing on certain threads. You've attempted to invoke blocking network api's on the ui thread of your application. Google has put in place a system that lets you know this is a bad idea and you can resolve this issue by executing your request in a separate thread or an asyncTask.

请阅读的博客文章。你可以找到关于做异步/多线程应用遍及信息,以便和谷歌。

Please read this blog post. You can find information about doing async / multi-threaded apps all over SO and Google.

这篇关于HonyComb和DefaultHttpClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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