一个学习Android的iOS开发人员提出的两部分问题,他正在开发一个Android项目,该项目将提出从JSON到图像到音频和视频的流媒体下载的各种请求:

在iOS上,我广泛使用AFNetworking项目。Android上有类似的库吗? 我已经阅读了Square的OkHTTP和Retrofit,以及Volley,但还没有使用它们开发的经验。我希望有人能够为每种方法提供一些最佳用例的具体示例。从我所读到的,OkHTTP似乎是三个中最健壮的,并且可以处理这个项目的需求(上面提到过)。


当前回答

AFNetworking for Android:

快速Android网络在这里

快速Android网络库支持所有类型的HTTP/HTTPS请求,如GET, POST, DELETE, HEAD, PUT, PATCH

快速Android网络库支持下载任何类型的文件

快速Android网络库支持上传任何类型的文件(支持多部分上传)

快速Android网络库支持取消请求

快速Android网络库支持设置优先级为任何请求(LOW, MEDIUM, HIGH, IMMEDIATE)

快速Android网络库支持RxJava

由于它使用OkHttp作为网络层,它支持:

快速Android网络库支持HTTP/2支持允许对同一主机的所有请求共享一个套接字

快速Android网络库使用连接池,减少请求延迟(如果HTTP/2不可用)

透明的GZIP压缩下载大小

快速Android网络库支持响应缓存,完全避免网络重复请求

谢谢:图书馆是我创建的

其他回答

我希望有人能够为每种方法提供一些最佳用例的具体示例。

如果您正在与Web服务通信,请使用Retrofit。如果您正在下载图像,请使用毕加索对等库。如果需要在Retrofit/Picasso之外执行HTTP操作,请使用OkHTTP。

Volley与Retrofit + Picasso大致竞争。好的方面是,它是一个库。缺点是,它是一个没有文档的、不受支持的、“把代码扔到墙上,然后在上面做一个I|O演示”的库。

编辑-排射现在正式支持谷歌。请参考谷歌开发者指南

据我所知,OkHTTP似乎是这三个中最健壮的

如果可以,Retrofit会自动使用OkHTTP。杰克·沃顿有个要点能把Volley和OkHTTP联系起来。

并能处理这个项目的要求(如上所述)。

根据“流媒体”的传统定义,你可能不会使用它们中的任何一个来“流式下载音频和视频”。相反,Android的媒体框架将为你处理这些HTTP请求。

也就是说,如果您打算尝试自己的基于http的流,OkHTTP应该处理这种情况;我不记得Volley会如何处理这种情况。无论是Retrofit还是Picasso都不是为此而设计的。

AFNetworking for Android:

快速Android网络在这里

快速Android网络库支持所有类型的HTTP/HTTPS请求,如GET, POST, DELETE, HEAD, PUT, PATCH

快速Android网络库支持下载任何类型的文件

快速Android网络库支持上传任何类型的文件(支持多部分上传)

快速Android网络库支持取消请求

快速Android网络库支持设置优先级为任何请求(LOW, MEDIUM, HIGH, IMMEDIATE)

快速Android网络库支持RxJava

由于它使用OkHttp作为网络层,它支持:

快速Android网络库支持HTTP/2支持允许对同一主机的所有请求共享一个套接字

快速Android网络库使用连接池,减少请求延迟(如果HTTP/2不可用)

透明的GZIP压缩下载大小

快速Android网络库支持响应缓存,完全避免网络重复请求

谢谢:图书馆是我创建的

RoboSpice Vs. Volley

从https://groups.google.com/forum/ # !主题/ robospice / QwVCfY_glOQ

RoboSpice(RS) is service based and more respectful of Android philosophy than Volley. Volley is thread based and this is not the way background processing should take place on Android. Ultimately, you can dig down both libs and find that they are quite similar, but our way to do background processing is more Android oriented, it allow us, for instance, to tell users that RS is actually doing something in background, which would be hard for volley (actually it doesn't at all). RoboSpice and volley both offer nice features like prioritization, retry policies, request cancellation. But RS offers more : a more advanced caching and that's a big one, with cache management, request aggregation, more features like repluging to a pending request, dealing with cache expiry without relying on server headers, etc. RoboSpice does more outside of UI Thread : volley will deserialize your POJOs on the main thread, which is horrible to my mind. With RS your app will be more responsive. In terms of speed, we definitely need metrics. RS has gotten super fast now, but still we don't have figure to put here. Volley should theoretically be a bit faster, but RS is now massively parallel... who knows ? RoboSpice offers a large compatibility range with extensions. You can use it with okhttp, retrofit, ormlite (beta), jackson, jackson2, gson, xml serializer, google http client, spring android... Quite a lot. Volley can be used with ok http and uses gson. that's it. Volley offers more UI sugar that RS. Volley provides NetworkImageView, RS does provide a spicelist adapter. In terms of feature it's not so far, but I believe Volley is more advanced on this topic. More than 200 bugs have been solved in RoboSpice since its initial release. It's pretty robust and used heavily in production. Volley is less mature but its user base should be growing fast (Google effect). RoboSpice is available on maven central. Volley is hard to find ;)

我最近发现了一个名为ion的库,它为桌面带来了一些额外的功能。

ion拥有内置的图像下载支持,集成了ImageView, JSON(在GSON的帮助下),文件和非常方便的UI线程支持。

我在一个新项目上使用了它,到目前为止效果还不错。它的使用比Volley或Retrofit简单得多。

Retrofit 1.9.0 vs RoboSpice

我在我的应用程序中使用这两种。

当我解析嵌套的JSON类时,Robospice比Retrofit工作得更快。因为Spice Manger会为你做任何事。在Retrofit中,您需要创建GsonConverter并反序列化它。

我在同一个活动中创建了两个片段,并使用两个相同类型的url同时调用。

09-23 20:12:32.830  16002-16002/com.urbanpro.seeker E/RETROFIT﹕   RestAdapter Init
09-23 20:12:32.833  16002-16002/com.urbanpro.seeker E/RETROFIT﹕ calling the method
09-23 20:12:32.837  16002-16002/com.urbanpro.seeker E/ROBOSPICE﹕ initialzig spice manager
09-23 20:12:32.860  16002-16002/com.urbanpro.seeker E/ROBOSPICE﹕ Executing the method
09-23 20:12:33.537  16002-16002/com.urbanpro.seeker E/ROBOSPICE﹕ on SUcceess
09-23 20:12:33.553  16002-16002/com.urbanpro.seeker E/ROBOSPICE﹕ gettting the all contents
09-23 20:12:33.601  16002-21819/com.urbanpro.seeker E/RETROFIT﹕ deseriazation starts
09-23 20:12:33.603  16002-21819/com.urbanpro.seeker E/RETROFIT﹕ deseriazation ends