问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/34403233/manually-retry-volley-request-on-android