In layman Rxjava

Source: Internet
Author: User

Rxjava (i: Basic article)

Easy to Rxjava (ii: operator)

In layman's Rxjava three--the benefits of reactive formula

In layman's Rxjava four-use responsive programming in Android

What the hell is RxJava?

One word: async .

Where's RxJava?

In other words, "the same is done asynchronously, why do people use it instead of ready-made asynctask/handler/xxx/...?" 』

One word: concise .

The advantage of RxJava is simplicity, but its simplicity is unique in that it remains concise as the program logic becomes more complex.

(a) Basic use 1, create a observable object, directly call Observable.create can [Java]View PlainCopy
  1. observable<string> myobservable = Observable.create (
  2. New Observable.onsubscribe<string> () {
  3. @Override
  4. public void Call (SUBSCRIBER<? Super String> Sub) {  
  5. Sub.onnext ("Hello, world!");
  6. Sub.oncompleted ();
  7. }
  8. }
  9. );
The observable object defined here simply emits a Hello world string, and then it ends.

2, create a subscriber to handle the string emitted by the observable object.

[Java]View PlainCopy
  1. subscriber<string> mysubscriber = new subscriber<string> () {
  2. @Override
  3. public void OnNext (String s) {System.out.println (s);}
  4. @Override
  5. public void oncompleted () {}
  6. @Override
  7. public void OnError (Throwable e) {}
  8. };

Here subscriber just prints the string that observable sent.

3, we can associate our defined Myobservable object with the Mysubscriber object through the Subscribe function, which completes the subscriber to observable subscription.

Myobservable.subscribe (Mysubscriber); Once Mysubscriber subscribes to Myobservable,myobservable, the OnNext and OnComplete methods of the Mysubscriber object are called, and mysubscriber prints the Hello world! (ii) operator

Map: A mapping, transformation, used to convert an event to another event.

FLATMAP: Smooth map, receive a observable output as input, and output another observable.

Filter: filters, outputs and inputs the same elements, and filters out those that do not meet the check conditions.

Doonnext (): Do some extra things before you output one element at a time

Take: Outputs a maximum of a specified number of results.

... See the official API documentation for more operators.

In-depth theory: RxJava for Android developers

In layman Rxjava

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.