rxjava-android官方介绍

人生必须的知识就是引人向光明方面的明灯。这篇文章主要讲述rxjava-android官方介绍相关的知识,希望能为你提供帮助。
Rxandroid: Reactive Extensions for AndroidAndroid specific bindings for  RxJava.
This module adds the minimum最小量的 classes to Rxjava that make writing reactive components组件 in Android applications easy and hassle-free省事. More specifically, it provides a  Scheduler调度程序  that schedules on the main thread or any given  Looper.
CommunicationSince RxAndroid is part of the RxJava family the communication channels are similar:

  • Google Group:  RxJava
  • Twitter:  @RxJava
  • StackOverflow:  rx-android
  • GitHub Issues
Binaries二进制文件
compile ‘io.reactivex:rxandroid:1.2.1‘ // Because RxAndroid releases are few and far between, it is recommended you also // explicitly depend on RxJava‘s latest version for bug fixes and new features. compile ‘io.reactivex:rxjava:1.1.6‘

  • RxAndroid: 
    rxjava-android官方介绍

    文章图片
  • RxJava: 
    rxjava-android官方介绍

    文章图片
Additional补充 binaries and dependency information for can be found at  http://search.maven.org.
BuildTo build:
$ git clone [email  protected]:ReactiveX/RxAndroid.git $ cd RxAndroid/ $ ./gradlew build

Further details on building can be found on the RxJava  Getting Started  page of the wiki.
rxjava-android官方介绍

文章图片

Sample usage【rxjava-android官方介绍】A sample project which provides runnable code examples that demonstrate演示 uses of the classes in this project is available in the  sample-app/  folder.
Observing on the main threadOne of the most common通常 operations处理 when dealing with asynchronous tasks on Android is to observe the task‘s result or outcome on the main thread. Using vanilla Android, this would typically通常 be accomplished熟练的、才华高的 with an  AsyncTask. With RxJava instead you would declare声明 your  Observable  to be observed on the main thread:
Observable.just("one", "two", "three", "four", "five") .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(/* an Observer */);

This will execute执行 the  Observable  on a new thread, and emit发射 results through  onNext  on the main thread.
Observing on arbitrary任意 loopersThe previous前面的 sample is merely仅仅 a specialization of a more general concept: binding asynchronous communication to an Android message loop, or  Looper. In order to observe an  Observable  on an arbitrary  Looper, create an associated合作的  Schedulerby calling  AndroidSchedulers.from:
Looper backgroundLooper = // ...Observable.just("one", "two", "three", "four", "five") .observeOn(AndroidSchedulers.from(backgroundLooper)) .subscribe(/* an Observer */)

This will execute the Observable on a new thread and emit results through  onNext  on whatever thread is runningbackgroundLooper.


来自为知笔记(Wiz)






    推荐阅读