How to increase timeout for retrofit requests in robospice android?

前端 未结 3 829
刺人心
刺人心 2021-02-07 19:02

I have implemented robospice in my project and using retrofit for all api calls. For some of requests, I need to increase timeout, please let me know how can I do that?

3条回答
  •  醉酒成梦
    2021-02-07 19:43

    In your RetrofitSpiceService extending service, you'll need to override createRestAdapterBuilder().

     @Override
     protected Builder createRestAdapterBuilder() {
        Builder builder = super.createRestAdapterBuilder();
        builder.setClient(new CustomClient());
        return builder;
      }
    

    CustomClient is the class that you need to write yourself to supply your own timeouts. If you're using OkHttp, take a look at the default OkClient for reference: https://github.com/square/retrofit/blob/43b7ea14e5aca1d710deccb95b79484b03e99bb9/retrofit/src/main/java/retrofit/client/OkClient.java

提交回复
热议问题