在Android上手动重试Volley请求 [英] manually retry Volley request on android

查看:55
本文介绍了在Android上手动重试Volley请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一个RetryPolicy可以使用,但是看起来它会自动执行重试.

我想要的是在用户单击重试"按钮时触发重试.我试图存储请求并重用它,但是发现Volley实际上在请求完成后会销毁侦听器.

这使我无法在重试后进行任何用户交互.但是,我可以再次重构相同的请求,但是它看起来不正确,并使事情变得更加复杂.

是否可以手动执行重试?还是留住听众?谢谢!

解决方案

您所经历的以及得出的结论与原样完全相同. imho背后的逻辑也很好.请求是具有状态的生物,它过着生命并死亡.你把球扔在海里的东西.球正在飞溅,然后下沉.您无法真正获得回球,而是获得了另一个完全相同的球并再次扔出.

请求包含的数据很重要,可以重用.您可以使用此数据,http方法和uri克隆/重新创建请求.当然,其他描述行为的参数,但是应该以更通用的方式获得.以类似的方式,我使请求在 jus 中变得可克隆,这是一个基于截击的库,但它有了更多的发展./p>

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.

这篇关于在Android上手动重试Volley请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆