0
我使用Retrofit 2.0
。为了充分利用REST类型的服务的一些数据我用的程序是这样的:改装取消请求
public Call downloadUser() {
// Create RetrofitService
Call<User> call = service.getUser();
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Response<User> response, Retrofit retrofit) {
// Do some operations with User obj if response.isSuccess()
}
@Override
public void onFailure(Throwable t) {
// Failure
}
});
return call;
}
在某些情况下,我要取消我的请求。我使用call.cancel()
,但即使我将此过程称为Callback.onResponse(...)
或Callback.onFailure(...)
,因此使用Call.cancel()
不会取消我的请求,并且它会一直持续到故障或响应。