RxAndroid README

The project's README from github.com/ReactiveX/RxAndroid. As one markdown file: README.md.

RxAndroid: Reactive Extensions for Android

Android specific bindings for RxJava 3.

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.

Communication

Since RxAndroid is part of the RxJava family the communication channels are similar:

Binaries

dependencies {
    implementation 'io.reactivex.rxjava3:rxandroid:3.0.2'
    // 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.
    // (see https://github.com/ReactiveX/RxJava/releases for latest 3.x.x version)
    implementation 'io.reactivex.rxjava3:rxjava:3.1.5'
}

Additional binaries and dependency information for can be found at search.maven.org.

Snapshots of the development version are available in Sonatype's snapshots repository.

repositories {
    mavenCentral()
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

dependencies {
    implementation 'io.reactivex.rxjava3:rxandroid:3.1.0-SNAPSHOT'
}

Build

To 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.

Sample usage

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 thread

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.

Observing on arbitrary loopers

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 running backgroundLooper.

Bugs and Feedback

For bugs, feature requests, and discussion please use GitHub Issues. For general usage questions please use the mailing list or StackOverflow.

LICENSE

Copyright 2015 The RxAndroid authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

RxAndroid (ReactiveX/RxAndroid)

Searching Database…

19.9K ·GitHub
这是什么?RxAndroid 为 RxJava 3 提供 Android 专用的绑定,只添加了在 Android 应用中轻松编写响应式组件所需的最少类。
这是独立的框架,还是 RxJava 的扩展?它是基于 RxJava 3 的小型扩展库,不是独立框架;主要新增了用于 Android 主线程或任意指定 Looper 的调度器(Scheduler)。
我该怎么把它添加到项目里?将 RxAndroid 依赖添加到你的 Android 项目中(快照版本可在 Sonatype 的 snapshots 仓库中获取);可参考 sample-app/ 文件夹中可运行的用法示例。
使用它之前,我需要先配置好 RxJava 吗?需要,RxAndroid 是 RxJava 3 的附加库,所以你的项目中需要同时包含 RxJava。
它在原生 RxJava 之外到底增加了什么?主要新增了 AndroidSchedulers,让你可以在主线程或自定义 Looper 上观察 Observable,而不必手动使用 AsyncTask。
我怎样在指定的 Looper 上观察,而不是主线程?创建一个 AndroidSchedulers.from(backgroundLooper) 调度器;Observable 会在新线程上运行,并通过 onNext 在运行该 Looper 的线程上发出结果。
有可以学习的示例代码吗?有,sample-app/ 文件夹中包含一个示例项目,其中有可运行的代码,演示了该库各个类的用法。
Creator
ReactiveX
Size
1 MB
Stars
19.9K
Age
12y
Commits · 90 Days