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