Recently studied Rxjava, has been looking at the great God's article, analysis.
Or to actually knock on the impression will be profound, to understand the RX mechanism.
A data source is a free API for aggregating data.
Complete data request with retrofit
The example is simple and nothing is more complicated than using the operator.
Is the simple network data acquisition.
Some commonly used operators can refer to the Official document description:
Reactivex/rxjava Document Chinese version
First look at the run:
APIs can be used to aggregate data on official website applications.
These are all get requests, so the notation is the same:
To create an interface:
Weatherapi { @GET("/onebox/weather/query?") Getweatherinfo (@Query("CityName") String phone, @Query("key") String key);}
Create Retrofit:
Public StaticWeatherapiGetweatherapi() {if(Weatherapi==NULL) {RetrofitRetrofit=NewRetrofit.builder (). BASEURL ("http://op.juhe.cn"). Addcalladapterfactory (rxjavacalladapterfactory.Create()). Addconverterfactory (gsonconverterfactory.Create()). Build (); Weatherapi=Retrofit. Create (Weatherapi.class); }returnWeatherapi;}
To subscribe to the trigger code in activity:
Rxview.clicks(Btn_check). Throttlefirst (3, Timeunit.SECONDS). Subscribe (NewAction1<void> () {@Override Public voidPager(Void aVoid) {NetWork.Getweatherapi(). Getweatherinfo (Et_city_name. GetText (). ToString (), Api_key). Subscribeon (schedulers.Newthread()). Observeon (androidschedulers.Mainthread()). Subscribe (NewAction1<weather> () {@Override Public voidPager(Weather Weather) {Setdispaly (weather); } }); } });
Examples can be downloaded in git for reference.
Https://github.com/VongVia1209/RxAndroid_Demo_With_jvhe
"Android Learning" Rxandroid learning using the interface of aggregated data