1

I have some network calls that takes can take more than a minute to respond, so i want to set requests timeout to 180 seconds.

I tried this code, but it looks like that after 60 seconds it cancels the request and does not read the timeout property.

This is my code.

            jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
                    (int) TimeUnit.SECONDS.toMillis(185),
                    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
dev90
  • 7,187
  • 15
  • 80
  • 153
  • 1
    yes used retrofit 2.0 –  Nov 27 '18 at 07:47
  • @Android Team, so its not possible with `volley` – dev90 Nov 27 '18 at 07:47
  • Possible duplicate of [Change Volley timeout duration](https://stackoverflow.com/questions/17094718/change-volley-timeout-duration) – karan Nov 27 '18 at 07:52
  • @KaranMer : I know how to change request duration, but i want to know the possibility of increasing timeout duration more than 60 seconds. – dev90 Nov 27 '18 at 08:02

1 Answers1

0

it is possible with retrofit 2. try this code below

int timeOut = 3 * 60; // duration in seconds
    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(timeOut, TimeUnit.SECONDS)
            .writeTimeout(timeOut, TimeUnit.SECONDS)
            .readTimeout(timeOut, TimeUnit.SECONDS)
            .build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("your netwrok url")
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .build();

YourRetrofitInterface service = retrofit.create(YourRetrofitInterface.class);
asif.ibtihaj
  • 361
  • 5
  • 14