我有一个API数组列表
allSignsList = ArrayList()
allSignsList.add(AllSignsList( "Overview", "overview.aspx"))
allSignsList.add(AllSignsList( "Details", "details.aspx"))
allSignsList.add(AllSignsList( "Description", "description.aspx"))
allSignsList.add(AllSignsList( "profile", "profile.aspx"))
我在allSignList数组中使用for循环发出请求,因为所有API的响应格式都相同。但是我面临的主要问题是结果不是按顺序排列的。我想等待请求完成,然后再调用另一个API。
我通过这种方式进行网络通话:
try {
mApiServiceNetwork.getNetworkServiceForXml(getNewXmlBaseUrl())
.getXmlTest(path)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Subscriber<RSSFeedItems>() {
override fun onCompleted() {
//Do nothing for now
}
override fun onError(e: Throwable) {
Log.e(TAG, "onError " + Log.getStackTraceString(e))
apiResult.onAPIFail()
}
override fun onNext(rssFeed: RSSFeedItems) {
Log.e(TAG+" Weekly", (MainActivity.weeklyCount++).toString() + " Operation performed successfully")
apiResult.onModel(rssFeed)
}
})
} catch (e: Exception) {
Log.e(TAG, "Exception" + Log.getStackTraceString(e))
apiResult.onError(e)
}