How to set timeout in Retrofit-2.0+ android

Configure OkHttpClient for timeout option. Then use this as client for Retrofit.Builder.

final OkHttpClient okHttpClient = new OkHttpClient.Builder()
    .connectTimeout(20, TimeUnit.SECONDS)
    .writeTimeout(20, TimeUnit.SECONDS)
    .readTimeout(30, TimeUnit.SECONDS)
    .build();

Use this okHttpClient for Retrofit#Builder

Retrofit.Builder()
    .client(okHttpClient);

Official OkHttp documentation about timeout is here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)