Android Web Service和网络库的比较:OKHTTP,Retrofit和Volley [英] Comparison of Android Web Service and Networking libraries: OKHTTP, Retrofit and Volley

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

问题描述

一个学习Android的iOS开发人员的一个分为两个部分的问题,该问题涉及一个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?

我已经阅读了 OkHTTP

I've read up on OkHTTP and Retrofit by Square, as well as Volley but don't yet have experience developing with them. I'm hoping someone could 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的正式支持.请参考 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会如何处理这种情况.既不是翻新也不是毕加索设计的.

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 Web Service和网络库的比较:OKHTTP,Retrofit和Volley的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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