有什么方法可以保留Volley请求,直到响应完成 [英] Is there Any way To hold Volley request until the response Completed

查看:77
本文介绍了有什么方法可以保留Volley请求,直到响应完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去使用AsyncTask时,我们有两种方法doInBackground()来完成所有工作,而onPostExecute()则是在所有数据恢复完成后进行更改,因此我可以停止所有代码,直到返回正确的数据,然后执行我需要的操作有了这些数据.

As past when use AsyncTask we have two method doInBackground() to do all work and onPostExecute() to make change when all data back completed, so I can stop all code until the right data come back, then do what I need with this data.

但是当我尝试移至Volley库时,当调用请求时,我只有onResponse()方法,但是有一个问题,我需要根据后台数据来做一些代码,但是无法在此保存代码点.

But when I try to move to Volley library, when call request I just have the onResponse() method, but there is problem that I need to do some code depend on back data but there is no way to hold code at this point.

那么有什么方法可以保留Volley请求,直到响应完成?

So is there Any way To hold Volley request until the response Completed ?

*我知道我们可以重写onResponse()来在完整数据返回时做我们需要的事情,但这当然是很多嵌套的编码和方法.

*I know we can override the onResponse() to do what we need when the full data come back,but this well be a lot of Nested coding and method.

感谢所有能提供帮助的人.

Thanks for all who can help.

推荐答案

如果希望同步执行请求,则可以使用RequestFuture等待返回响应.不应在主线程上执行此操作,因为这会导致您的UI锁定.

If you are looking to synchronously perform a request you could use a RequestFuture to wait until the response has been returned. This should not be done on the main thread, as it will cause your UI to lock up.

在这里也得到了回答: https://stackoverflow.com/a/18541806

This has been answered as well here: https://stackoverflow.com/a/18541806

这篇关于有什么方法可以保留Volley请求,直到响应完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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