我正在关注这个tutorial . 虽然我已成功采用rxAndroid来避免由循环视图引起的 Exception
,但我正在从改造中丢失 Response
对象 .
我最初的要求是......
interface UserRepo {
@GET("user")
fun get(): Call<User>
}
// then call it by
userRepo.get().enqueue(callback)
其中 callback
将具有 Response
对象,但在将上述内容转换为...
interface UserRepo {
@GET("user")
fun get(): Single<User>
}
// then call it by
mCompositeDisposable.add(userRepo.get()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ success ->
// todo success
},
{ error ->
// todo error
}
)
)
我基本上无法从回调中访问 Response
. 我确实需要状态代码 . 知道怎么样?
谢谢
1 回答
而不是
Single<T>
,让它返回Single<Response<T>>
.