【发布时间】:2018-01-08 09:59:36
【问题描述】:
这个问题听起来很简单,但我很难。
我可以这样用改造 2 来发帖:
class RetrofitClient {
private static Retrofit retrofit = null;
static Retrofit getClient(String baseUrl) {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
API服务接口:
@POST("postsInit")
@FormUrlEncoded
Call<InitPost> postInit(
@Field("appVersion") String versionName,
@Field("appId") String applicationId,
);
最后:
apiService.postInit(versionName, applicationId).enqueue(new Callback<InitPost>() {
@Override
public void onResponse(@NonNull Call<InitPost> call, @NonNull Response<InitPost> response) {
if (response.isSuccessful()) {
Timber.d("post submitted to API");
getInitResponse();
}
}
@Override
public void onFailure(@NonNull Call<InitPost> call, @NonNull Throwable t) {
if (call.isCanceled()) {
Timber.e("Request was aborted");
} else {
Timber.e("Unable to submit post to API.");
}
}
});
如何将其转换为 RxJava 2 ?我已经实现了转换器工厂,但互联网上没有关于同时使用 rxJava 2 和改造 2 的信息。
【问题讨论】:
标签: android rx-java retrofit2 rx-java2