rx-java 设置Retrofit和RxJava
示例
Retrofit2带有对多种可插入执行机制的支持,其中一种是RxJava。
要与RxJava一起使用改造,首先需要将RetrofitRxJava适配器添加到您的项目中:
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
那么在构建改造实例时需要添加适配器:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.example.com")
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();在您定义API的界面中,返回类型应为Observable:
public interface GitHubService {
@GET("users/{user}/repos")
Observable<List<Repo>> listRepos(@Path("user") String user);
}您也可以使用Single代替Observable。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短