<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>difference between Volley and Retrofit Archives - Truiton</title>
	<atom:link href="https://www.truiton.com/tag/difference-between-volley-and-retrofit/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Technology Reaching Us In Time - Online</description>
	<lastBuildDate>Sun, 01 Sep 2019 15:10:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.truiton.com/wp-content/uploads/2022/11/cropped-truiton_new_logo_half_white.png?fit=32%2C32&#038;ssl=1</url>
	<title>difference between Volley and Retrofit Archives - Truiton</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">54534495</site>	<item>
		<title>Android Volley vs Retrofit &#124; Better Approach?</title>
		<link>https://www.truiton.com/2015/04/android-volley-vs-retrofit-better-approach/</link>
					<comments>https://www.truiton.com/2015/04/android-volley-vs-retrofit-better-approach/#comments</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Sat, 04 Apr 2015 17:10:16 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[difference between Volley and Retrofit]]></category>
		<guid isPermaLink="false">http://www.truiton.com/?p=1035</guid>

					<description><![CDATA[<p>Now-days almost every Android app uses a REST web API for data transfer. This makes me think what are the best practices to parse data and images from a REST web service. Earlier I used to prefer, writing my own code for parsing data. But now we have a whole range of REST client libraries,&#8230;&#160;<a href="https://www.truiton.com/2015/04/android-volley-vs-retrofit-better-approach/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Android Volley vs Retrofit &#124; Better Approach?</span></a></p>
<p>The post <a href="https://www.truiton.com/2015/04/android-volley-vs-retrofit-better-approach/">Android Volley vs Retrofit | Better Approach?</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter"><a href="https://www.flickr.com/photos/nanagyei/5273976253"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="950" height="534" data-attachment-id="1036" data-permalink="https://www.truiton.com/2015/04/android-volley-vs-retrofit-better-approach/android-volley-vs-retrofit/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Volley-vs-Retrofit.jpg?fit=950%2C534&amp;ssl=1" data-orig-size="950,534" data-comments-opened="1" data-image-title="Android Volley vs Retrofit" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Volley-vs-Retrofit.jpg?fit=950%2C534&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Volley-vs-Retrofit.jpg?resize=950%2C534" alt="Photo Credit: Nana B Agyei - Android Volley vs Retrofit" class="wp-image-1036" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Volley-vs-Retrofit.jpg?w=950&amp;ssl=1 950w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Volley-vs-Retrofit.jpg?resize=300%2C169&amp;ssl=1 300w" sizes="(max-width: 950px) 100vw, 950px" /></a></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Now-days almost every Android app uses a REST web API for data transfer. This makes me think what are the best practices to parse data and images from a REST web service. Earlier I used to prefer, writing my own code for parsing data. But now we have a whole range of REST client libraries, which can speed up the development, by reducing coding efforts and parsing data efficiently. Android Volley and Retrofit are two of the most used libraries for accessing REST web APIs today. For any one choosing between them is a difficult task. In this article we will not only compare Android Volley vs Retrofit, but will also discuss, out of these two, taking which one would be a better approach.</p>



<p class="wp-block-paragraph">Research has proven that using an external library like Android Volley or Retrofit, definitely reduces time taken to parse a response. Therefore&nbsp;if you are building up a new project, I would strongly recommend to use either one of them to enhance your development. These libraries not only ease the development effort but also, give you many great features like retry mechanism, automatic parsing of data and caching. Although these libraries can increase the size of your apk a little, but still they are worth it. Before starting the comparison let me first introduce these libraries:</p>



<h3 class="wp-block-heading">Volley Library:</h3>



<p class="wp-block-paragraph">Volley is a networking library, developed by Google engineers. It was introduced in Google IO 2013, it offers great features like synchronous requests, asynchronous requests, prioritization, making multiple requests at the same time, ordered requests and of course caching. But one of the major problems faced by developers using this library is that it lacks detailed official documentation. Hence if you wish to learn more about it please refer to some of my tutorials:</p>



<ol class="wp-block-list"><li><a title="Android Volley Example" href="http://www.truiton.com/2015/02/android-volley-example/" target="_blank" rel="noopener noreferrer"> Android Volley Tutorial</a></li><li><a title="Android Volley | Making A Synchronous Request" href="http://www.truiton.com/2015/02/android-volley-making-synchronous-request/" target="_blank" rel="noopener noreferrer">Synchronous Volley Request</a></li><li><a title="Android Volley ImageLoader and NetworkImageView Example" href="http://www.truiton.com/2015/03/android-volley-imageloader-networkimageview-example/" target="_blank" rel="noopener noreferrer">Loading Images Through Volley</a></li></ol>



<h3 class="wp-block-heading">Retrofit Library v1.9.0:</h3>



<p class="wp-block-paragraph">On the other hand Retrofit is a clean, simple, and light library for Android by <a title="Square, Inc." href="http://square.github.io/" target="_blank" rel="noopener noreferrer">Square, Inc</a>. In other words, Retrofit is a REST client for Android, through which you can make easy to use interfaces which can turn any Android app into a powerful one. What makes it different is that, Retrofit can perform Async and sync requests with automatic JSON parsing without any effort. This feature alone makes it powerful enough to make a contender for this comparison. Although it has many more easy to use features, please refer to one of my tutorials to read more about them:</p>



<ol class="wp-block-list"><li><a title="Android Retrofit Tutorial" href="http://www.truiton.com/2015/04/android-retrofit-tutorial/" target="_blank" rel="noopener noreferrer">Android Retrofit Example</a></li></ol>



<h2 class="wp-block-heading">Android Volley vs Retrofit</h2>



<h3 class="wp-block-heading">1) Request Execution</h3>



<p class="wp-block-paragraph">One of the most important factors effecting the code complexity is, how a request is executed in your code. In background or in foreground? As you may know that Android OS does not allow the network interaction on main thread, it throws a NetworkOnMainThreadException. To avoid this you may need to do all the network processing in background. As a matter of fact both Android Volley and Retrofit support the background requests. Also both of them are designed in a way, that you may not have to write huge amounts of code to perform such requests. Although if you wish to do a request in foreground, even that it possible in both. As there are situations when you may want to block user from going further ahead in your app until a response is captured from web API.</p>



<h3 class="wp-block-heading">2) In-Built Request Types</h3>



<p class="wp-block-paragraph">The data returned from a web service always complicates the implementation, but thankfully now with help of these libraries almost all types of responses can be captured. Android Volley can capture four types of responses automatically through these requests:</p>



<ol class="wp-block-list"><li><code>StringRequest</code> &#8211; Make this type of request and the returned data is parsed and converted in to a <code>String</code>.</li><li><code>JsonObjectRequest</code> &#8211; This type of request converts the response in to a <code>JSONObject</code>.</li><li><code>JsonArrayRequest</code> &#8211; Make this type of request and response is automatically converted into a <code>JSONArray</code>.</li><li><code>ImageRequest</code> &#8211; This type of request converts the response into a decoded bitmap automatically.</li></ol>



<p class="wp-block-paragraph">On the other hand Retrofit can parse many other types of responses automatically like:</p>



<ol class="wp-block-list"><li><code>Boolean</code> &#8211; Web API response needs to be a String boolean.</li><li><code>Integer</code> &#8211; Web API response needs to be an integer.</li><li><code>Date</code>&#8211; Web API response should be Long format date.</li><li><code>String</code> &#8211; Web API response needs to be in String format.</li><li><code>Object</code> &#8211; Web API response needs to be in Json object.</li><li><code>Collections</code> &#8211; Web API response needs to be in a String Format.</li></ol>



<p class="wp-block-paragraph">Now when comparing Android Volley vs Retrofit, volley may have image parsing feature but it cannot convert a Json object directly into a POJO (Plain Old Java Object). On the other hand retrofit can automatically convert a JSON object into a POJO, but lacks image parsing.</p>



<h3 class="wp-block-heading">3) Retry Mechanism</h3>



<p class="wp-block-paragraph">One of the great things about volley is that it supports retries on request timeout. While creating requests with volley, we can set a retry policy by using <code>setRetryPolicy</code> method. By default a volley request timeout time is set to 5 seconds. But if you wish to change the policy, it supports that too. You can specify these parameters according to your needs:</p>



<ul class="wp-block-list"><li>Timeout</li><li>Number Of Retries</li><li>Back Off Multiplier</li></ul>



<p class="wp-block-paragraph">Retrofit on the other hand does not have a retry mechanism as of now. Although I just saw their road map for 2.0 version, they might have a retry mechanism then. Therefore as of now when comparing Android Volley vs Retrofit, Retrofit loses this one.</p>



<h3 class="wp-block-heading">4) Caching</h3>



<p class="wp-block-paragraph">Android Volley library has a very elaborate caching mechanism. This is one of the best features of volley. When a request is made through volley first it is checked in the cache. If an appropriate response is present in cache then it is parsed and returned directly to main thread, else a network request is made. This whole functionality can be customized, to support your requirements. If you wish to learn more about it please go through this <a title="Android Volley Caching" href="http://developer.android.com/training/volley/requestqueue.html">document</a>.</p>



<p class="wp-block-paragraph">Retrofit on the hand, does not support caching. Although it can implement <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html" target="_blank" rel="noopener noreferrer">RFC 2616 caching</a> which is the spec for HTTP caching, through the OkHttpClient. As stated in this <a title="Android Retrofit Caching" href="https://github.com/square/retrofit/issues/678" target="_blank" rel="noopener noreferrer">document</a>. Therefore when comparing caching between Android Volley and Retrofit, Volley takes this one too.</p>



<h3 class="wp-block-heading">5) Loading Images</h3>



<p class="wp-block-paragraph">Volley library has a special type of request to get images from network called <code>ImageRequest</code>. When this type of request is made, response is captured as a bitmap. Also it supports the resizing of returned image in the worker thread itself, which saves a lot of coding. Volley also has a <code>NetworkImageView</code> class which can be used with <code>ImageLoader</code> class, to automatically load images, whenever the <code>NetworkImageView</code> appears. Read <a title="Android Volley ImageLoader and NetworkImageView Example" href="http://www.truiton.com/2015/03/android-volley-imageloader-networkimageview-example/" target="_blank" rel="noopener noreferrer">this tutorial</a> for more information about it.</p>



<p class="wp-block-paragraph">As of now Retrofit does not support the loading of images, the way they are loaded in Volley. But it can be combined with OkHttpClient to support the loading of images. Hence volley takes this one too.</p>



<h3 class="wp-block-heading">6) Code Complexity</h3>



<p class="wp-block-paragraph">Both the libraries Android Volley and Retrofit are very easy to implement. If you compare them with primitive ways of accessing a web API, both of them would come out as a winner as they can phenomenally reduce your code base. But in my opinion when you compare the Android Volley vs Retrofit, the later one- Retrofit wins this one. As there is not much to customize in Retrofit. Its a simple yet powerful library. Volley on the other hand is highly customizable and has a greater code complexity.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">After thoroughly comparing the major features between Android Volley and Retrofit. In my personal opinion Volley is a better library. It may be a little complex but it offers much more features than Retrofit. Volley not only supports caching of requests but can also load images automatically. But one of the best things about Retrofit is that it supports automatic parsing of responses, to their respective data types. And its light too. Hope this Android Volley vs Retrofit comparison helped you. Connect with though Facebook, Google+, and Twitter for more updates.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2015/04/android-volley-vs-retrofit-better-approach/">Android Volley vs Retrofit | Better Approach?</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2015/04/android-volley-vs-retrofit-better-approach/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1035</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.truiton.com @ 2026-08-11 15:22:49 by W3 Total Cache
-->