在java 这样写
Subscription subscribe = observable
.subscribeOn(Schedulers.newThread())//请求网络在子线程中
.observeOn(AndroidSchedulers.mainThread())//回调在主线程中
.subscribe(new Subscriber<BaseRespose<T>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(BaseRespose<T> baseResponseVo) {
}
});
而在kotlin 这样写
val subscribe = observable!!
.subscribeOn(Schedulers.newThread())//请求网络在子线程中
.observeOn(AndroidSchedulers.mainThread())//回调在主线程中
.subscribe(
{
baseResponse ->
LogUtil.getInstance().e(baseResponse.toString())
LogUtil.getInstance().e("onNext")
},
{
t ->
LogUtil.getInstance().e(t.message.toString())
LogUtil.getInstance().e("onError")
},
{
LogUtil.getInstance().e("onComplete")
}
)