所有通话和回拨都可以。我只是有一个问题,我在回调中使用http错误代码克隆并重试一个调用(使用相同的回调)。
public static abstract class MyCallback<T> implements Callback<T> {
@Override
public void onResponse(Call<T> call, retrofit2.Response<T> response) {
Timber.d("is this the main thread %b", Looper.myLooper() == Looper.getMainLooper());
if (response.isSuccessful()) {
//success handling
} else {
if (response.code() == 406) {
// remedy reason for failure
call.clone().enqueue(MyCallback.this);
}
}
}
@Override
public void onFailure(Call<T> call, Throwable t) {
Timber.e("onFailure %s", t.getMessage());
}
}
这给出了:
is this the main thread true
is this the main thread false
is this the main thread false
is this the main thread false
is this the main thread false
[looping]
我玩过其他/新的回调,开始新的调用等。只有当我克隆调用时,才会从主线程调用回调。 出现的实际问题是,在成功重试呼叫后我无法更改UI。
使用Retrofit 2.0.1