HonyComb and DefaultHttpClient HonyComb and DefaultHttpClient android android

HonyComb and DefaultHttpClient


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.


Thanks Nick. It worked for me. For dev purpose I just set the Thread Policy to default by doing this

*ThreadPolicy tp = ThreadPolicy.LAX;StrictMode.setThreadPolicy(tp);*

This should be removed for the final version.


abhinaw's suggestion written as reflection, so code also works on older API versions:

   try {        Class strictModeClass=Class.forName("android.os.StrictMode");        Class strictModeThreadPolicyClass=Class.forName("android.os.StrictMode$ThreadPolicy");        Object laxPolicy = strictModeThreadPolicyClass.getField("LAX").get(null);        Method method_setThreadPolicy = strictModeClass.getMethod(                "setThreadPolicy", strictModeThreadPolicyClass );        method_setThreadPolicy.invoke(null,laxPolicy);    } catch (Exception e) {    }

Yes, this should be removed for the final version.