Why should I use OkHttp instead of android httpClient and AsyncTask
Asked Answered
D

1

20

In the presentation of Paresh Mayani at SpeakerDeck (https://speakerdeck.com/pareshmayani/lazy-android-developers-be-productive) he says that it's better to use OkHttp or Retrofit instead of AsyncTask with DefaultHttpClient.

My question is why?
Why are they faster?
Aren't those also libraries based on the default android classes?
What is the difference between OkHttp and Retrofit ?

Decelerate answered 9/9, 2014 at 8:10 Comment(0)
F
22

As always, engineering is about balancing the trade-offs to build the best solution for your requirements.

Using a library instead of the platform is a good example. The API of the platform has existed for quite some time, and for compatibility reasons the Android team has less flexibility in changing those interfaces. A library doesn't have those constraints; for example, if the host supports it OkHttp can use the SPDY protocol for lower latency, compression, multiplexing, etc., which can make your Android app more responsive.

OkHttp and Retrofit - which are projects from Square - can work together. They are also regular Java libraries, so they do not depend on / based on Android. OkHttp handles the lower-level HTTP connection details, while Retrofit simplifies using REST APIs. Retrofit can be used on top of OkHttp, but it is not required.

Check out the projects websites, they are also hosted on github.

http://square.github.io/okhttp/

http://square.github.io/retrofit/

Furfuran answered 19/9, 2014 at 17:59 Comment(1)
I didn't understand this explanation, If anyone please help me.Shu

© 2022 - 2024 — McMap. All rights reserved.