我正面临这个问题,当我打电话给改装时,这个电话不会在断点处停止。
ClashResponse clashResponse = new ClashResponse();
clashApi = clashResponse.getClashApi();
clashApi.getAllArenas().enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
ClashApiBuilder<ArenaData> clashApiBuilder = new ClashApiBuilder(ArenaData.class);
arenaList = clashApiBuilder.convert(String.valueOf(call));
}
@Override
public void onFailure(Call<String> call, Throwable t) {
t.getCause();
}
});
我的傻瓜
//Retrofit
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
我的改造建造者:
public ClashResponse(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(SERVER_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit.create(ClashApi.class);
}
答案 0 :(得分:1)
如果你想调试你的Api调用使用chuck拦截器它只能在调试模式下工作。在您的应用build.gradle中添加以下依赖项。
debugCompile 'com.readystatesoftware.chuck:library:1.1.0'
releaseCompile 'com.readystatesoftware.chuck:library-no-op:1.1.0'
获取okHttp3
public OkHttpClient getClient(Context context) {
// Add the interceptor to OkHttpClient
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(new ChuckInterceptor(context));
builder.readTimeout(READ_TIMEOUT, TimeUnit.MINUTES);
builder.connectTimeout(CONNECT_TIMEOUT, TimeUnit.MINUTES);
return builder.build();
}
现在获取Retrofit实例并添加此okHttp
客户端
public RestApi connectToApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_DOC_URL)
//Data converter
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(getClient(context))
.build();
return retrofit.create(RestApi.class);
}
现在您可以通过通知栏跟踪所有Api电话。