Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetworkOnMainThreadException [duplicate]

I just found out about NetworkOnMainThreadException at official docs

and was wondering if the emulator is throwing this. I have been testing my app quite a bit and as far as I know all networking is off the main thread (using Roboguice RoboAsyncTask) but you never know if one has not escaped.

I am also using StrictMode and have not seen anything.

  1. Is my code just clean or is this not thrown on the emulator?

  2. How are we supposed to prepare for this happening in production?

  3. What about a grace period or something? Or is that elapsed now ;-) ??

like image 576
Manfred Moser Avatar asked Mar 01 '11 04:03

Manfred Moser


1 Answers

With honeycomb you can not perform a networking operation on its main thread as documentation says. For this reason you must use handler or asynctask. There is no another way to do it.

here you can find 2 examples written in turkish about networking operation. maybe they help.

  • 3. party kütüphane kullanmadan (ksoap2), (it includes english translation)

  • AsyncTask class'tan dönen parametreyi handle etmek. , google translate

like image 150
Mustafa Güven Avatar answered Oct 04 '22 21:10

Mustafa Güven