Does Volley execute UI thread operations when my a

2019-08-17 00:40发布

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条回答
我只想做你的唯一
2楼-- · 2019-08-17 01:06

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.

查看更多
登录 后发表回答