question about asynchronous http
I just want to check if I understood well the way asynchronous Http request work on Android.
Suppose I make such a request and set a ResponseHan开发者_如何学运维dler<String> responseHandler
to handle the response. By doing this is it possible to have the UI thread blocked waiting for the response ? The implication being that the code in the function:
public String handleResponse(HttpResponse response)
is also executed on the UI thread or is there silently spawned a thread that waits for the response and calls the handleResponse(HttpResponse response) function when the response arrives ?
By doing this is it possible to have the UI thread blocked waiting for the response ?
Calling execute()
with or without a ResponseHandler
will block that thread until the HTTP request has been processed. If you call execute()
on the main application thread, you will block the UI. This is not a good thing -- use AsyncTask
to execute()
on a separate thread, then use your onPostExecute()
implementation to update your UI with the results of the request.
精彩评论