Rxjava Line Program Control system

Source: Internet
Author: User

Observable.just (1, 2, 3, 4)    //  Specify Subscribe () occurs on IO thread    //  specified subscriber Callback occurs in the main thread    . Subscribe (new action1<integer>() {        @Override        public  void call (Integer number) {            "number:" + number );}    });

Thread switching through the compose operator

public class Schedulertransformer<t> implements Observable.transformer<t, t> {    @Override    public Observable<t> Call (observable<t> Observable) {        return Observable                . Subscribeon (Schedulers.io ())                . Observeon (Androidschedulers.mainthread ());    }    public static <T> schedulertransformer<t> Create () {        return new schedulertransformer<> ();}    }

Use:

Observable.just (1, 2, 3, 4)    . Compose (schedulertransformer.  <Integer>  Create ())  //One line of code for thread switching     . Subscribe (newpublicvoid call ( Integer number) {LOG.D (tag, "number:" + number);}});

Free switching of threads

Observable.just (1, 2, 3, 4)//IO thread, specified by Subscribeon ()    . Subscribeon (Schedulers.io ())    . Observeon ( Schedulers.newthread ())    . Map (Mapoperator)//new thread, specified by Observeon ()     . Observeon (Schedulers.io ())    . Map (MapOperator2)//IO thread, specified by Observeon ()    . Observeon (Androidschedulers.mainthread)     . Subscribe (subscriber);  Android main thread, specified by Observeon ()
Pass observeOn()Multiple invocations of a thread, and the program implements multiple switching of threads. differs from observeOn()subscribeOn() can be placed anywhere, but it is only called once.。

Rxjava Line Program Control system

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.