How to have a reliable Volley request with no retries policy

主宰稳场 提交于 2019-12-21 17:10:32

问题


When I am on a slow connection and making a POST request, Volley retries my request multiple times and after it all ends up hitting my errorListener. Sometimes, these retries actually succeeded in posting data.

The user will assume that the request failed, but in truth, if they refreshed the data they'd see the data was POSTed twice to the server (or however many successful retries in the bunch).

I want give Volley a very dumbed-down retry policy:

I want it to try a request for 15 seconds and if the request doesn't reach the server within 15 seconds and comes back with a response to trigger the errorListener. I don't want it to retry at all.

The only concern is if Volley tries, the request gets to the server within 20~25 seconds, but by then it triggered the errorListener and the data still got POSTed.

Does HTTP follow a time-limit after which it is 100% the data won't get posted because the request took too long? Like maybe 40 seconds? If such, then I can have the request go on for 40 seconds.

In all:

No retries and ensure 100% that if data got posted on first try go to successListener and if it didn't get posted (request died due to taking too long or error response from server) errorListener.

I was thinking of doing something with the defaultRetryPolicy... like DefaultRetryPolicy(15000, 0, 1), though I think the last parameter doesn't matter because what is the point of back-off with no retries.

How would I achieve what I asked two paragraphs back?

来源:https://stackoverflow.com/questions/28457952/how-to-have-a-reliable-volley-request-with-no-retries-policy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!