0

I have already set a connection with API, everything seems to be working but I need to set a timeout for data to show. I have checked the answers from before here on StackOverflow, but none of the methods seem to fit. Do you know any way of how to set the timeout right?

I tried several codes from these answers (How to set connection timeout with OkHttp) and there was always some issues with it. At this point, I have an error that says that it cannot resolve the method setReadConnection

OkHttpClient client = new OkHttpClient.Builder().setReadTimeout(30, TimeUnit.SECONDS).build();

I was just hoping that this would help me to finally show the data in the app. Thanks for any tips

Albína Mrázová
  • 253
  • 1
  • 2
  • 11

1 Answers1

1

Is that you looking for?

OkHttpClient okHttpClient = new OkHttpClient.Builder()
            //default timeout for not annotated requests
            .readTimeout(10000, TimeUnit.MILLISECONDS)
            .connectTimeout(10000, TimeUnit.MILLISECONDS)
            .writeTimeout(10000, TimeUnit.MILLISECONDS)
            .build();
hemen
  • 1,460
  • 2
  • 16
  • 35