标签:lin ref canonical example als groovy tco apple import
Android 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
.
Since RxAndroid is part of the RxJava family the communication channels are similar:
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‘
Additional补充 binaries and dependency information for can be found at http://search.maven.org.
To build:
$ git clone git@github.com:ReactiveX/RxAndroid.git
$ cd RxAndroid/
$ ./gradlew build
Further details on building can be found on the RxJava Getting Started page of the wiki.
A sample project which provides runnable code examples that demonstrate演示 uses of the classes in this project is available in the sample-app/
folder.
One 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.
The 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合作的 Scheduler
by 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
.
标签:lin ref canonical example als groovy tco apple import
原文地址:http://www.cnblogs.com/baiqiantao/p/61461845a63c472074d99f8972757323.html