Skip to content

nelson1110/RxJava2-Android-Samples

 
 

Repository files navigation

通过Example来学习RxJava2 for Android

Mindorks Android Arsenal Open Source Love License

如何在Android 应用中使用RxJava2

如何从 RxJava 1 迁移到 RxJava 2

谁适合阅读这个项目 :

  • 正在迁移到RxJava2的人
  • 刚刚开始学习RxJava2的人

只需要构建编译这个项目,赶紧开始通过example来学习吧.

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.

Migration From RxJava 1 to RxJava 2

To allow having RxJava 1 and RxJava 2 side-by-side, RxJava 2 is under the maven coordinates io.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.

在你的app中引入RxJava2

在你的build.gradle中加入下面的代码

compile 'io.reactivex.rxjava2:rxjava:2.0.6'

如果你也正在用RxAndroid, 你还需要加入下面的代码

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

RxJava 2 Examples present in this sample project

  • RxJava 2.0 Example using CompositeDisposable as CompositeSubscription and Subscription have been 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

简单来看一下RxJava2和RxJava1的区别

RxJava1 -> RxJava2

  • onCompleted -> onComplete - 没有了后面的字母 d
  • Func1 -> Function
  • Func2 -> BiFunction
  • CompositeSubscription -> CompositeDisposable
  • limit 这个操作符移除了,改用 - take in RxJava2
  • and much more.

操作符 :

  • Map -> transform the items emitted by an Observable by applying a function to each item
  • Zip -> combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function
  • Filter -> emit only those items from an Observable that pass a predicate test
  • FlatMap -> transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable
  • Take -> emit only the first n items emitted by an Observable
  • Reduce -> apply a function to each item emitted by an Observable, sequentially, and emit the final value
  • Skip -> suppress the first n items emitted by an Observable
  • Buffer -> periodically gather items emitted by an Observable into bundles and emit these bundles rather than emitting the items one at a time
  • Concat -> emit the emissions from two or more Observables without interleaving them
  • Replay -> ensure that all observers see the same sequence of emitted items, even if they subscribe after the Observable has begun emitting items
  • Merge -> combine multiple Observables into one by merging their emissions

example中的亮点 :

TODO

  • Many examples are to be added

Find this project useful ? ❤️

  • Support it by clicking the ⭐ button on the upper right of this page. ✌️

Check out an awesome MVP architecture based project which uses RxJava2, Dagger2.

Check out an awesome library for fast and simple networking in Android.

Another awesome library for debugging databases and shared preferences.

###Check out Mindorks awesome open source projects here

Contact - Let's become friend

License

   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.

Contributing to RxJava 2 Android Samples

Just make pull request. You are in!

About

RxJava 2 Android Examples - Migration From RxJava 1 to RxJava 2 - How to use RxJava 2 in Android

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%