volley--reading carding

Source: Internet
Author: User

With one months of spare time after work, read the volley source code, the front also recorded the reading process, this is designed to comb the volley workflow.

In general, we use volley, the process is very simple. Create a request, build a new requestqueue, and finally add the request to the Requestqueue, then we can wait for the requested response, and if it's stringrequest, We can directly get the string type response.

So, Requestqueue is how to round to request,request and how to send HTTP requests, and then get a response, the response step by step into response, finally, response and how to become the final string, The previous article reads the code one line at a line, and here's a small summary.

1.RequestQueue is a blocking queue, and when requested, it sends a request, and when it does not, it blocks the thread on which it is located. So, whenever a request joins Requestqueue, it will work and the queue is empty, waiting for the request.

2. The request will first complete the connection and other related processes in httpstack, including adding a cookie, judging the request type, add params to the POST request body. Will eventually get a HTtpresponse.

3.HttpResponse will give Network, the network handles the response of the HTTP request primarily, including the exception response such as 20x,304,404. Then, extract the header and content from the HttpResponse and create the networkresponse.

4. The above 2.3 methods are performed in Networkdispatcher, and after completion,response<?> Response = Request.parsenetworkresponse ( Networkresponse); The networkresponse will be converted to response, which is called in the request.

5. At the same time, in Networkdispatcher, Executordelivery will accept request and response, and call Mrequest.deliverresponse (Mresponse.result); Generates a string-type response.

The above is the approximate flow of a volley request.

done~

volley--reading carding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.