Google Volley vs Android-Async-Http

不打扰是莪最后的温柔 提交于 2019-12-04 11:19:36

问题


I am looking into both these Android Http Networking libraries.

I would like some peoples experiences with using the two libraries. Personally I have always used the http://loopj.com/android-async-http/ library quite happily. But it was recently suggested to me to use the Volley Framework.

What benefits will I get from one over the other?
From my reading so far, Volley incorporates a number of nice features such as Image Loading, Request Caching, Request Cancelling all in one library.

My current use case / specifications:

Consume web services from my android applications.

  • Receive JSON Objects from web service
  • Easy To integrate with the GUI
  • Stability and Reliability over raw performance
  • Long term maintenance and support of the library.
  • Ease of use / ease of implementation

From some reading up on SE:

"Volley is all good but, On the minus side, it is one undocumented, unsupported, "throw the code over the wall and do an I|O presentation on it" library."

So I think its clear Volley might get the tick for features, But how well documented and maintained is it? If I decide to use it will there still be support for it 4 years down the line?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/25346813/google-volley-vs-android-async-http

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