androidnetwork-programmingretrofitandroid-networking

Comparison of Android networking libraries: OkHTTP, Retrofit, and Volley


Two-part question from an iOS developer learning Android, working on an Android project that will make a variety of requests from JSON to image to streaming download of audio and video:

  1. On iOS I have used the AFNetworking project extensively. Is there an equivalent library for Android?

  2. I've read up on OkHTTP and Retrofit by Square, as well as Volley but dont yet have experience developing with them. I'm hoping someone can provide some concrete examples of best use cases for each. From what I've read, seems like OkHTTP is the most robust of the three, and could handle the requirements of this project (mentioned above).


Solution

  • I'm hoping someone can provide some concrete examples of best use cases for each.

    Use Retrofit if you are communicating with a Web service. Use the peer library Picasso if you are downloading images. Use OkHTTP if you need to do HTTP operations that lie outside of Retrofit/Picasso.

    Volley roughly competes with Retrofit + Picasso. On the plus side, it is one library. On the minus side, it is one undocumented, an unsupported, "throw the code over the wall and do an I|O presentation on it" library.

    EDIT - Volley is now officially supported by Google. Kindly refer Google Developer Guide

    From what I've read, seems like OkHTTP is the most robust of the 3

    Retrofit uses OkHTTP automatically if available. There is a Gist from Jake Wharton that connects Volley to OkHTTP.

    and could handle the requirements of this project (mentioned above).

    Probably you will use none of them for "streaming download of audio and video", by the conventional definition of "streaming". Instead, Android's media framework will handle those HTTP requests for you.

    That being said, if you are going to attempt to do your own HTTP-based streaming, OkHTTP should handle that scenario; I don't recall how well Volley would handle that scenario. Neither Retrofit nor Picasso are designed for that.