人生必须的知识就是引人向光明方面的明灯。这篇文章主要讲述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
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:
文章图片
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.
文章图片
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合作的
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
.来自为知笔记(Wiz)
推荐阅读
- android基础知识之一
- Android 自定义属性
- 安卓中的数据存储方式以及ContentProvider的简单介绍
- [修正] Firemonkey Android Edit 可输入 Emoji (颜文字)
- Android学习笔记---Material Design设计理念
- 安卓多线程间通信和多进程之间通信有什么不同?分别怎么实现?
- android 应用架构随笔五(ActionBar与侧滑菜单DrawerLayout)
- Android(onNewIntent()触发机制及注意事项)
- Android Studio快捷键