我在一个应用程序上工作,我曾经使用Rx-android和Retrofit来做网络请求,但现在项目中有一个要求,我必须做嵌套的网络呼叫。我试图谷歌它,但没有发现任何好的article.If任何人已经在这个主题上工作,然后请让我知道你的发现。
发布于 2019-06-26 11:51:56
假设您使用的是rxjava适配器的改进:
fun firstRequest(): Single<Response<String>>
fun secondRequest(idFromFirstRequest: String): Single<Response<ResponseBody>>使用flatmap操作员链接网络呼叫:
firstRequest()
// do more operators on the request, like transforming the object, or showing it first on the ui
.flatMap { stringId -> secondRequest(stringId) }
// you can flatMap here again to chain another network requests
// .flatMap { thirdRequest() }
// .flatMap { fourthRequest() }
// and so on...发布于 2019-06-26 12:49:26
有各种与API链接相关的文章,最简单的实现方法是使用Rx-Java方法
1)使用RxJava压缩运算符的(用于并行请求)
2)使用RxJava flatMap() 运算符(依次串行请求)
有关更详细的示例,请参阅这两个链接
https://stackoverflow.com/questions/56764884
复制相似问题