RxJava 2.0 has been completely rewritten from scratch on top of the Reactive-Streams specification. The specification itself has evolved out of RxJava 1.x and provides a common baseline for reactive systems and libraries.
Because Reactive-Streams has a different architecture, it mandates changes to some well known RxJava types.
To allow having RxJava 1 and RxJava 2 side-by-side, RxJava 2 is under the maven coordinatesio.reactivex.rxjava2:rxjava:2.x.y and classes are accessible below io.reactivex.
Users switching from 1.x to 2.x have to re-organize their imports, but carefully.
Add this in your build.gradle
compile 'io.reactivex.rxjava2:rxjava:2.2.2'
If you are using RxAndroid also, then add the following
compile 'io.reactivex.rxjava2:rxandroid:2.1.0'
RxJava 2.0 Example using CompositeDisposable
as CompositeSubscription
and Subscription
havebeen removed.
RxJava 2 Example using Flowable
.
RxJava 2 Example using SingleObserver
, CompletableObserver
.
RxJava 2 Example using RxJava2 operators such as map, zip, take, reduce, flatMap, filter, buffer, skip, merge, concat, replay
, and much more:
RxJava 2 Android Samples using Function
as Func1
has been removed.
RxJava 2 Android Samples using BiFunction
as Func2
has been removed.
And many others android examples
RxJava1 -> RxJava2
onCompleted
-> onComplete
- without the trailing dFunc1
-> Function
Func2
-> BiFunction
CompositeSubscription
-> CompositeDisposable
limit
operator has been removed - Use take
in RxJava2Map
-> transform the items emitted by an Observable by applying a function to each itemZip
-> combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this functionFilter
-> emit only those items from an Observable that pass a predicate testFlatMap
-> transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single ObservableTake
-> emit only the first n items emitted by an ObservableReduce
-> apply a function to each item emitted by an Observable, sequentially, and emit the final valueSkip
-> suppress the first n items emitted by an ObservableBuffer
-> periodically gather items emitted by an Observable into bundles and emit these bundles rather than emitting the items one at a timeConcat
-> emit the emissions from two or more Observables without interleaving themReplay
-> ensure that all observers see the same sequence of emitted items, even if they subscribe after the Observable has begun emitting itemsMerge
-> combine multiple Observables into one by merging their emissionsSwitchMap
-> transform the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed ObservableCompositeDisposable
Flowable
and reduce
operatorSingleObserver
CompletableObserver
map
Operatorzip
Operator, Blog for referencebuffer
Operatortake
Operatorreduce
Operatorfilter
Operatorskip
Operatorreplay
Operatorconcat
Operatormerge
Operatordefer
ObservableswitchMap
ObservableInterval
debounce
, switchMap
, distinctUntilChanged
, Blog for referenceconcat
, firstElement
, Blog for reference Copyright (C) 2016 Amit Shekhar
Copyright (C) 2011 Android Open Source Project
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.
Just make pull request. You are in!
最近工作不那么忙,计划重新搭建一个MVP架构!基于Rxjava2-Rxandroid首先掌握RxJava2的使用的方式! 此文章是根据老外amitshekhariitbhu的RxJava2-Android-SamplesDemo 改装而成,是个翻译版本,足够应付对RxJava2的全部姿势! GitHub地址: RxJava2-Android-Samples Map - >通过对每个项应用函数来变换
定义 RxJava 提供一套异步编程的 API,这套 API 是基于观察者模式的,而且是链式调用的,所以使用 RxJava 编写的代码的逻辑会非常简洁。 相关基础 观察者模式 当对象间存在一对多关系时,则使用观察者模式(Observer Pattern)。比如,当一个对象被修改时,则会自动通知依赖它的对象。观察者模式属于行为型模式。应用场景示例:微信公众号的订阅功能。 观察者模式简单实现 参考:
从去年(2015)10月份左右接触到RxJava到今(2016.03)也有近半个年,从一开始的Rx风格的蒙圈代码到现在自己项目中必不可少的Lib,多多少少积累下来一些经验,再加上周边小伙伴不时的问这个依赖(RxJava)是什么?这代码什么意思?RxJava是什么?能做什么?很牛B吗?- -!有时候真的问的人无言以对。 1、Rxjava是什么(响应式编程)
何时调用subscribeWith方法而不是普通的Subscribe?用例是什么? VS 谢谢你 根据文档,这两个实例都返回一次性的SingleObserver实例: 其中ConsumerSingleObserver类实现SingleObserver和Disable。
我做错了什么?我如何将结果与可观察的结果结合起来?最好不是用Lamda符号。 我查看的其他资源:-android rxjava2/retrofit2链接调用与分页令牌
我正在android中学习RxJava2。谁能解释一下,我们如何使用RxJava2将数据插入SQLiteDatabase。这里是我试图使用的代码示例,但它将数据插入数据库六次; //OnClick(单击) //可观察 //观察员 //添加方法
可观察的如下所示。
我使用REST API查询Person对象列表。最大限制是100人响应。我需要把所有的人都叫来,总数不详。第一个响应中有一个名为“next”的字段,包含下一页的url。我需要使用rxjava/rxandroid和referfit链接这些调用,直到最后一个响应有一个空的“next”字段。由于“Next”字段包含分页url,所有后续调用都将具有与第一个不同的url。做这件事最方便的方法是什么?
我有一个自定义对象列表(