Does Volley execute UI thread operations when my app comes to the foreground?

萝らか妹 提交于 2019-12-25 00:53:17

问题


I have a button that calls requestQueue.add method of the Volley library. Inside the onResponse method i call:

    popupBox.display(getString(R.string.successfulRegistration), false, true); 

Display method, displays a popup window thus must be called inside UI thread.

I put a break point at the beginning of the onResponse method.

Immediately after clicking on the button, switch to another app and send my app to the background.

IDE stops on the break point and I get my answer from the server but my app still is in the background and there is no exception error.

After about a minute, I bring my app to the foreground. After that, the message window pops up.

Is that mean, I don't need to check if I can do something related to UI thread inside the onResponse method because volley handles it?


回答1:


onResponse and onErrorResponse are called on main thread by default unless you are trying to call them from some other tread. Volley makes the Api call on a non ui thread (non UI blocking). Volley doesn't take care of your life cycle. So, if you make a api call in an activity and close that activity, the callback are received. So, you should check whether the activity is in foreground or not.



来源:https://stackoverflow.com/questions/52425061/does-volley-execute-ui-thread-operations-when-my-app-comes-to-the-foreground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!