简体   繁体   English

在Android上手动重试Volley请求

[英]manually retry Volley request on android

I know there's a RetryPolicy to use, but looks like it performs retry automatically. 我知道有一个RetryPolicy可以使用,但是看起来它会自动执行重试。

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. 我试图存储请求并重用它,但是发现Volley实际上在请求完成后会销毁监听器。

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. imho背后的逻辑也很好。 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. 您可以使用此数据,http方法和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. 以类似的方式,我在jus上使请求变得可克隆, jus是一个基于齐射的图书馆,但仍在不断发展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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