All Projects → xinghongfei → Hello Rxjava

xinghongfei / Hello Rxjava

可能是学习Rxjava最好的教程之一,另一个是《给Android开发者RxJava的详解》,这个毫无疑问。

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Hello Rxjava

Android Mvvm
MVVM on Android using RxJava and Data Binding
Stars: ✭ 443 (-15.78%)
Mutual labels:  rxjava
Rxpaparazzo
RxJava extension for Android to take images using camera and gallery and pick files up
Stars: ✭ 467 (-11.22%)
Mutual labels:  rxjava
Rxretrojsoup
A simple API-like from html website (scrapper) for Android, RxJava2 ready !
Stars: ✭ 492 (-6.46%)
Mutual labels:  rxjava
Rxbasicskata
Practical challenges for RxJava learners
Stars: ✭ 449 (-14.64%)
Mutual labels:  rxjava
Android Mvp Architecture
This repository contains a detailed sample app that implements MVP architecture using Dagger2, GreenDao, RxJava2, FastAndroidNetworking and PlaceholderView
Stars: ✭ 4,360 (+728.9%)
Mutual labels:  rxjava
Bilibili Android Client
An unofficial bilibili client for android http://www.jianshu.com/p/f69a55b94c05 -- 该项目已停止维护!
Stars: ✭ 4,430 (+742.21%)
Mutual labels:  rxjava
Ferro
Simple and powerful MVP library for Android
Stars: ✭ 441 (-16.16%)
Mutual labels:  rxjava
Rxfirebase
Rxjava 2.0 wrapper on Google's Android Firebase library.
Stars: ✭ 509 (-3.23%)
Mutual labels:  rxjava
Livedata Ktx
Kotlin extension for LiveData, chaining like RxJava
Stars: ✭ 466 (-11.41%)
Mutual labels:  rxjava
Rxjavafx
RxJava bindings for JavaFX
Stars: ✭ 489 (-7.03%)
Mutual labels:  rxjava
Rxfile
Rx methods to get a File and Image or Video thumbnails from a Document Provider on Android (Drive, Dropbox etc)
Stars: ✭ 452 (-14.07%)
Mutual labels:  rxjava
Mdplayer
🔥 MDPlayer,Android万能播放器,支持视频大小窗口无缝切换,基于ijklayer+MVP+RxJava+Retrofit+Material Design开发。
Stars: ✭ 463 (-11.98%)
Mutual labels:  rxjava
Viabus Architecture
让 Android 开发可以像流水线一样高效的,职责分离架构 ⚡ 不同于 MVP 的配置解耦,也不能和 似是而非 的 MVVM - Clean 同日而语。VIABUS 是世界范围内首个明确提出,通过职责分离,来真正实现 UI 和 业务并行开发的 Android 项目级开发架构和设计模式理念。
Stars: ✭ 485 (-7.79%)
Mutual labels:  rxjava
Gank
干货集中营 app 安卓实现,基于 RxFlux 架构使用了 RxJava、Retrofit、Glide、Koin等
Stars: ✭ 444 (-15.59%)
Mutual labels:  rxjava
Vertx Guide For Java Devs
Vert.x 3 guide for Java developers
Stars: ✭ 500 (-4.94%)
Mutual labels:  rxjava
Roxie
Lightweight Android library for building reactive apps.
Stars: ✭ 441 (-16.16%)
Mutual labels:  rxjava
Reprint
A unified fingerprint library for android.
Stars: ✭ 467 (-11.22%)
Mutual labels:  rxjava
Android Starter
[Android Architecture] Android starter based on MVP/Dagger2/RxJava2/Robolectric/Espresso/Mockito. It provides a generator to fast create a Android template project.
Stars: ✭ 522 (-0.76%)
Mutual labels:  rxjava
Traceur
Easier RxJava2 debugging with better stacktraces
Stars: ✭ 502 (-4.56%)
Mutual labels:  rxjava
Rxanimations
Repository for android animations Rx wrapper
Stars: ✭ 488 (-7.22%)
Mutual labels:  rxjava

Learning RxJava(RxJava详解)

为什么做这个项目: 学习Rxjava,基本所有人都会看扔物线的《给Android开发者Rxjava的详解》,可以说是国内最理想的Rxjava教程了。这片文章后半部分讲对线程的操作,相信很多人都不太懂。这个项目通过最简单的方式,对Rxjava线程操作的进行讲解,让大家彻底明白Rxjava的核心内容。所以,在学习这个项目前先看扔物线大哥的文章。

RxJava的精妙之处就是异步操作极其方便,也就是Schedulers的使用,本项目可以让大家彻底掌握Schedulers的使用,还有常用的操作符、RxAndroid...的使用详解。就是用最简单移动的方式把Rxjava讲明白.

详解 (Details Explain)

我们可以把Schedulers看作线程控制符,一共五种线程控制符,可以通过这些线程控制符切换不同的线程。以下是五种线程控制符的区别:

  1. Schedulers.immediate() 在当前线程运行,相当于不切换线程。这是默认的 Scheduler。

  2. Schedulers.newThread()总是启用新线程,并在新线程执行操作。

  3. Schedulers.io() I/O 操作(读写文件、数据库、网络信息交互等)所使用的 Scheduler。行为模式和 newThread() 差不多,区别在于 io() 的内部实现是是用一个无数量上限的线程池,可以重用空闲的线程,因此多数情况下 io() 比 newThread() 更有效率。不要把计算工作放在 io() 中,可以避免创建不必要的线程。

  4. Schedulers.computation() 计算所使用的 Scheduler。这个计算指的是 CPU 密集型计算,即不会被 I/O 等操作限制性能的操作,例如图形的计算。这个 Scheduler 使用的固定的线程池,大小为 CPU 核数。不要把 I/O 操作放在 computation() 中,否则 I/O 操作的等待时间会浪费 CPU。

  5. AndroidSchedulers.mainThread() 切换到主线程,指定的操作将在Android 主线程运行。

其实我们常用的就2种:Schedulers.io()和AndroidSchedulers.mainThread()

以下几个例子都是使用Observable.just(1,2,3)创建被观察对象,观察者输出1,2,3.

This example show how to use make a few threads that we can watch their actions

1. 基本使用

2. 使用 subscribeOn(Schedulers.io())设置被观察者的线程

以下几个例子中看不出被观察者发生在什么线程,使用Observeble.create()创建被观察者可以看出发生在什么线程,可参看源码中的其它Demo。

3. 使用 subscribeOn(Schedulers.io()) 和 observeOn() 设置被观察者和观察者的线程

4. 使用Schedulers.io()指定被观察者产生事件的线程,然后使用Map对数据转换,这里只是在每个数据后面加‘a’。

5. 使用Schedulers.io()指定被观察者产生事件的线程,使用Map对数据转换,在每个数据后面加‘a’,使用AndroidSchedulers.mainThread()切换到主线程,然后使用Map变换,每个数据后加‘b’,输出结果。

6. 使用Schedulers.io()指定被观察者产生事件的线程,使用Map对数据转换,在每个数据后面加‘a’,使用AndroidSchedulers.mainThread()切换到主线程,然后使用Map变换,每个数据后加‘b’,再用Schedulers.io()切换线程,用Map对数据加‘c’,输出结果。

7.这个例子不同的是使用了两次subscribeOn()来指定被观察者的线程,最终最上面的subscribeOn()起作用,下面的subscribeOn()不起作用。然后使用Map对数据转换,这里只是在每个数据后面加‘a’,使用Schedulers.io()切换线程,然后使用Map变换,每个数据后加‘b’,再用AndroidSchedulers.mainThread()切换主线程,用Map对数据加‘c’,最后再切换到非主线程,输出结果。

最终发现设置被观察者的线程只有最上面的起作用,下面的不起作用。

更多的例子请看源码

About me

An android developer in Beijing.Welcome to offer me an Interview invitation. If you have any new idea about this project, feel free to contact me. 😃

License

Copyright 2016 Maat


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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].