"Android Learning" Rxandroid learning using the interface of aggregated data

Source: Internet
Author: User

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

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.