Rxjava和Retrofit的使用

添加依赖,最新的版本在github上查看。
implementation ‘com.squareup.okhttp3:okhttp:3.11.0’
implementation ‘com.squareup.okhttp3:logging-interceptor:3.11.0’
implementation ‘com.squareup.retrofit2:retrofit:2.4.0’
implementation ‘com.squareup.retrofit2:converter-gson:2.4.0’
implementation ‘com.squareup.retrofit2:converter-scalars:2.4.0’
implementation ‘com.squareup.retrofit2:adapter-rxjava2:2.4.0’ //进行支持rxjava2
implementation “io.reactivex.rxjava2:rxjava:2.2.2”
implementation ‘io.reactivex.rxjava2:rxandroid:2.1.0’

1.使用注解,进行标识接口和参数
在这里插入图片描述
2.需要创建Retrofit的对象,设置基地址,添加拦截器等
在这里插入图片描述
3.进行使用
在这里插入图片描述
使用rxjava2的形式
在这里插入图片描述

具体的demo:https://github.com/yunzheyue/rxjavaAndRetrofitTest

猜你喜欢

转载自blog.csdn.net/yuezheyue123/article/details/83112195