2

I've been using AsyncTasks for the past year to access a server and retrieve data, but is it a bad idea to use AsyncTasks for this purpose?

I see a lot of people using librariea such as Retrofit and others to handle their network operations.

Should I be using some third party libraries (or even Google's Volley) to handle this kind of requests?

Mauricio Silva
  • 483
  • 1
  • 5
  • 13

2 Answers2

5

Async task are basic Android way to handle task out of UI thread.

Async task have so many limitation like no orientation-change support, no ability to cancel network calls, as well as no easy way to make API calls in parallel.

With respect to networking 2 things are very important

  • speed
  • parallel request

Retrofit win in both speed and parallel network calls , volley is next and Async task is roughly 3 times slower than Retrofit for single request and 13 times slower for 25 request.

Clearly using Async task is bad idea

enter image description here

Image source http://instructure.github.io/blog/2013/12/09/volley-vs-retrofit/

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
2

There are a lot of issues with AsyncTasks such as: No orientation, change support no ability to cancel network calls, no easy way to make API calls in parallel.

Basically it means only one AsyncTask is running at a time and it requires multiple API calls run extremely slow.

Rather us Retrofit. You can cleanly and dynamically substitute path-segments, POST/GET variables, into the endpoint and its super fast.

Ryan Godlonton-Shaw
  • 584
  • 1
  • 5
  • 18