3
public interface AppApi
{
@GET("/api?action=" + ApiManager.API_USER)
Observable<JsonObject> getUser();
}
whith Retrofit 2.0 beta1
。我無法獲得響應?Retrofit 2.0 beta1
改造2.0測試版不supprot觀察的,現在呢?
public interface AppApi
{
@GET("/api?action=" + ApiManager.API_USER)
Observable<JsonObject> getUser();
}
whith Retrofit 2.0 beta1
。我無法獲得響應?Retrofit 2.0 beta1
改造2.0測試版不supprot觀察的,現在呢?
現在需要RxJava的適配器。
你可以從changeLog
得到消息新:CallAdapter(和工廠)提供擴展點支持多個 執行機制。 RxJava實現由 兄弟模塊提供。
試試下面的代碼和問題可以得到解決。
在app/的build.gradle
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
compile 'io.reactivex:rxandroid:0.24.0'
在Java代碼中
(如您的活動)
retrofit = new Retrofit.Builder().baseUrl(YOUR_END_POINT)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.(other options.....)
.build();
現在,你將與RxJava
作品你可以寫這樣的看法。
public interface AppApi {
@GET("/api")
Observable<JsonObject> getUser(@Query("action") String api_user);
}
這裏是你如何添加適配器:改裝改型=新Retrofit.Builder() .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) – Defuera
看看關於新改造大文章http://inthecheesefactory.com/博客/改裝的2.0/EN –