添加依赖

1
2
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1'
compile 'io.reactivex:rxandroid:1.0.1'

添加AddCallAdapterFactory

1
2
3
4
5
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.stay4it.com/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();

返回Observable

1
2
3
4
5
6
public interface APIService {
@POST("list")
Call<DessertItemCollectionDao> loadDessertList();
@POST("list")
Observable<DessertItemCollectionDao> loadDessertListRx();
}