Google Volley vs Android-Async-Http

余生长醉 提交于 2019-12-03 06:15:01
Sotti

Volley and Android Async Http are different things.

  • Android Async Http: Is a powerful Http client. Offers some functionalities as REST helper and integration for JSON parsing with other libraries.

  • Volley: Is a REST helper/library that helps you to deal with async requests and image loading. Volley it's not an http client. Volley uses the SDK http clients (the apache or the httpclient depending on the API level) if you don't provide one, but a common client for volley is OkHttp (https://goo.gl/nl2DfN). You can integrate Volley with Gson easily as well.

From my point of view, as much responsibility you give to a single library, less customization you have and more unneeded code you'll add. That's the reason libraries as Android Async Http or ION are losing grip nowadays and other options like the Square solutions (Okio + OkHttp + Retrofit + Moshi + Picasso - Those are five libraries) are gaining grip. So here you have 5 libraries that can be used separately as standalone or tied together as 2, 3 or 4. That's flexibility and power.

For further reading on this take a look at this answer.

We are currently using a combination of Volley and GSON in our application. There is nothing we haven't been able to do, and we use just about every type of HTTP request you can imagine. This currently includes:

  • Normal HTTP requests with JSON response
  • POST requests with form encoded data as well as raw byte arrays
  • Multipart HTTP requests with large objects such as images and files
  • Custom request headers
  • Internationalized requests

We have yet to run into a roadblock we could not overcome, though we had to write a fair amount of code to support all these features and build the framework we wanted, but that should be expected with any HTTP library.

Also Volley comes with an ImageLoader which handles caching of images, as well as a bunch of other nifty features.

Difference between Android Volley and AsyncTask

Try this link http://www.truiton.com/2015/02/android-volley-vs-asynctask-better-approach/

Using AsyncTask has been a good approach, but consider Android Volley as a 2.0 version of it. It has many improvements over AsyncTask, as volley is designed for the purpose of network access. A major advantage of Android Volley over AsyncTask is that you can do multiple requests simultaneously without the overhead of thread management. Also I believe retry mechanism is a great feature of volley which gives it an edge over AsynTask. Another advantage of volley over AsyncTask is that it provides you with multiple request types, through which complex requests can be made easily. On the other hand while using AsyncTasks one would have to create this type of request manually.

Although best approach differs from application to application. Like if you have less no of requests to make, you can use AsyncTask. As for volley, one has to import a library project which increases your project size. Hence pick wisely between volley and AsyncTask. Hope this Android Volley vs AsyncTask sum up helped you choose.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!