Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

android - HonyComb and DefaultHttpClient

In my code I have this

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

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

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)".

After this I see the following:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...