简体   繁体   中英

manually retry Volley request on android

I know there's a RetryPolicy to use, but looks like it performs retry automatically.

what I want is to trigger the retry when user clicks the retry button. I tried to store the request and reuse it but found that Volley actually destroys listeners after request is completed.

that makes me no way to do any user interaction after the retry. I can however reconstruct the same request again but it doesn't look right and is making things more complicated.

Is there a way to perform a retry manually? or keep the listeners? Thanks!

What you have experienced and the conclusion you came to is exactly as it is. The logic behind imho it is perfectly fine as well. The Request is a creature with states, it lives its life and it dies. Thing of a ball you throw in the sea. The ball is flying splashes and then sinks. You cannot get really get the ball back, instead you get another exactly the same ball and throw it again.

The data that the request contains is important and can be reused. You can clone/recreate the request using this data, the http method and the uri. Of course other parameters describing the behaviour but those should be obtained in a more generic way. In a similar way i made the request clonable in jus , a library based on volley but much more evolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM