0

When I'm sending request in my onCreate() method I'm receiving networkonmainthreadexception exception, but it works well when I'm sending request in onResume() method. What's difference? Is there any independent thread for onResume method or what?

Hayk Nahapetyan
  • 4,322
  • 8
  • 40
  • 59
  • Are you using a separate thread in onResume()? – FD_ Feb 17 '14 at 08:04
  • No , I didn't declare any thread in my project. – Hayk Nahapetyan Feb 17 '14 at 08:05
  • Strange then... Anyway, although it works, move your networking stuff into a background thread. Always. – FD_ Feb 17 '14 at 08:07
  • 2
    It shouldn't work in either. Networking in ANdroid needs to be done in its own thread or AsyncTask. It can not be done on the main thread. This is for responsiveness and to avoid tripping watchdog timers – Gabe Sechan Feb 17 '14 at 08:07
  • As in my project user must wait for response and must not continue working before getting response that's why I didn't use threads in whole application – Hayk Nahapetyan Feb 17 '14 at 08:10
  • That does not matter. The whole device might be blocked while you do the networking. – FD_ Feb 17 '14 at 08:18

1 Answers1

-1

Check this link which contains the details for OnCreate() method & OnResume() method. And don't ever try to call or Send Request from main thread or ui thread to get saved from getting network on main thread exception always i suggest to_Send Request or Call any web service_ in background using Async Task check this link for that. Also check this link for reference of OnResume() method hope this helps.

Community
  • 1
  • 1
i.n.e.f
  • 1,743
  • 13
  • 22