Skip to content Skip to sidebar Skip to footer

Network In UI Thread In An Android Device(android 3.0 Or Newer)

I have to parse a website html code and show some info in my app So I tried JSoup for getting result It works great on the emulator but in a real device it will crashes; here is th

Solution 1:

In Android 3.0 and newer, you're banned from touching the network or file IO on the UI thread. This is a good thing since it forces you to not interrupt the user interface for operations that may take a long time. Look at this line in your log:

05-25 21:42:20.940: E/AndroidRuntime(32230): Caused by: android.os.NetworkOnMainThreadException

You've already figured out where the exception is thrown, now you need to put that code in the doInBackground() method of an AsyncTask.


Post a Comment for "Network In UI Thread In An Android Device(android 3.0 Or Newer)"