Rxjava call Retrofit the process of executing a network request

Source: Internet
Author: User

Retrofit Flowchart-1. Rxjava calls retrofit, obtains the observer observable from Requestgtpushsaeuserinfo (), and then a new observer subscribes to it  0. Initiating a network request from the business call the specific interface Robotapiservice is the retrofit required interface file  1. A new Retrofit object is created in the Robotapiservice file to add Rxjava2calladapterfactory objects to generate Rxjava2calladapter,retrofit Retrofit =  New retrofit.builder (). BASEURL (Appconstants.get_ip_addr () +  "/"). Client (Builder.build ())//okhttp The client object. Addconverterfactory (Gsonconverterfactory.create ()). Addcalladapterfactory ( Rxjava2calladapterfactory.create ()). build (); 2.Retrofit objects call Create () to generate a proxy object for the API interface. Retrofit.create (Robotapiservice.class); 3. In the proxy object, intercept the method that needs to be executed by the agent, and construct a Servicemethod object through the method object. Executes the adapt () of the Calladatper interface. While the specific Calladapter implementation object Rxjava2calladapter is in the Loadservicemethod () method new  Servicemethod object, Based on the return value type of the method object: Observable.class, which is queried from the list contained in the retrofit object, and when is the list added? Is the 4 added to Addcalladapterfactory () when the new retrofit object is above.The last step of the code is to execute the adapt () of the Calladatper interface, calladapter the implementation object of the interface Rxjava2calladapter adapt (); Observable is created by the Observer bodyobservable, and the observable object is returned. 5. Return to 1 items, call the Subcribe () method (the base class method) of the returned observable object (actually the Bodyobservable object), The subscribeactual () is executed and the subscribeactual () in the Bodyobservable object associates the Observer observable with the Observer observer. When you call the Subscribeactual () method, you call Upstream's subscribe (), which is 4. The first red box on the picture in the item callobservable subscribe () in the execution of Subscribeactual () 6.Execute () executing call in Callobservable's Subscribeactual () performs a network request to fetch the result of the server, and then passes it to the Observer Observer.onnext (), Where observer is the Bodyobserver object in the red box, and the Bodyobserver object executes Observer.onnext (Response.body ()); When the Observer object is-1. The new Baseobservable object in the item, to which the network request is completed

Rxjava call Retrofit the process of executing a network request

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.