Search This Blog

Tuesday 24 July 2012

Exception networkonmainthreadexception in Android


Exception networkonmainthreadexception in Android



This exception is due to the StrictMode introduced on honeycomb or later android devices to not allow the network operations in main thread.


The solution to this exception is that you implement a thread for network operation instead of implementing in main thread.


The alternative method is to disable the option which is enable by default in honeycomb and later android OS.The previous versions of android OS allowed the main thread to create the network connections.


Disabling the StrictMode in Android


StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);


If you like the solution please provide your comments.


Thanks
Creative Android Apps

No comments:

Post a Comment