我将 Retrofit 与 RoboSpice 结合使用。我在某些地方进行了 REST 调用,但是一个调用是一个问题,因为从未调用过响应监听器 - onRequestFailure() 和 onRequestSuccess() 均未调用
Activity
...在用户选择 UI 选项之后
CreateCustomerRequest createCustomerRequest = new CreateCustomerRequest("1001", "John", "Smith");
this.getSpiceManager().execute(createCustomerRequest, new CreateCustomerRequestListener());
private class CreateCustomerRequestListener implements com.octo.android.robospice.request.listener.RequestListener<ErrorResponse> {
@Override
public void onRequestFailure(SpiceException spiceException) {
// Never called
}
@Override
public void onRequestSuccess(ErrorResponse errorResponse) {
// Never called
}
}
请求
public class CreateCustomerRequest extends RetrofitSpiceRequest<ErrorResponse, EmbarApi> {
private String id;
private String firstName;
private String lastName;
public CreateCustomerRequest(String id, String firstName, String lastName) {
super(ErrorResponse.class, EmbarApi.class);
this.id = id;
this.firstName = firstName;
this.lastName= lastName;
}
@Override
public ErrorResponse loadDataFromNetwork() throws Exception {
return getService().createCustomer(id, firstName, lastName);
}
我对为什么没有调用听众感到困惑。我看到来自 RS 的日志记录很少(只是“主要向请求队列添加请求”)这看起来很奇怪,但据我所知,RoboSpice 完全失败了,但完全没有提示。这特别令人困惑,因为我在应用程序中进行其他 REST 调用没有问题。
最佳答案
希望您不要忘记调用 spiceManager.start 和 spiceManager.shouldStop 函数。
它们应该分别在该上下文的 onStart 和 onStop 函数中调用。
关于android - 为什么不调用 Robospice 响应监听器方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24807673/