Android 网络库比较:OkHTTP、Retrofit 和 Volley [英] Comparison of Android networking libraries: OkHTTP, Retrofit, and Volley

查看:25
本文介绍了Android 网络库比较:OkHTTP、Retrofit 和 Volley的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 在 iOS 上,我广泛使用了 AFNetworking 项目.是否有适用于 Android 的等效库?

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

我已经阅读了 OkHTTPRetrofit by Square 以及 Volley 但还没有与他们一起开发的经验.我希望有人可以为每个人提供一些最佳用例的具体示例.从我读到的内容来看,OkHTTP 似乎是三者中最健壮的,并且可以处理这个项目的要求(如上所述).

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).

推荐答案

我希望有人可以为每个用例提供一些最佳用例的具体示例.

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

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

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 大致与 Retrofit + Picasso 竞争.从好的方面来说,它是一个图书馆.不利的一面是,它是一个未记录的、不受支持的将代码扔到墙上并在其上进行 I|O 演示"库.

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.

编辑 - Google 现在正式支持 Volley.请参阅 Google 开发者指南

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

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

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

如果可用,Retrofit 会自动使用 OkHTTP.有一个 Jake Wharton 的 Gist 将 Volley 连接到 OkHTTP.

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).

根据流媒体"的传统定义,您可能不会将它们用于音频和视频的流媒体下载".相反,Android 的媒体框架会为您处理这些 HTTP 请求.

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.

话虽如此,如果您打算尝试进行自己的基于 HTTP 的流式传输,OkHTTP 应该处理这种情况;我不记得 Volley 会如何处理这种情况.Retrofit 和 Picasso 都不是为此而设计的.

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.

这篇关于Android 网络库比较:OkHTTP、Retrofit 和 Volley的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆