Skip to content

changjiashuai/RxJava2-Android-Sample

Repository files navigation

Learning RxJava 2 for Android by example

Open Source Love License

How to use RxJava 2 in Android Application

This project is for :

  • who is migrating to RxJava 2
  • or just started with RxJava.

Just Build the project and start learning RxJava by examples.

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.

Using RxJava 2.0 Library in your application

Add this in your build.gradle

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

If you are using RxAndroid also, then add the following

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

Quick Look on few changes done in RxJava2 over RxJava1

RxJava1 -> RxJava2

  • onCompleted -> onComplete - without the trailing d
  • Func1 -> Function
  • Func2 -> BiFunction
  • CompositeSubscription -> CompositeDisposable
  • limit operator has been removed - Use take in RxJava2
  • and much more.

Examples Structure

	com.rxjava2.android.samples.ui.operators
		combining
			AndTheWhenExampleActivity
			CombineLatestExampleActivity
			...
		conditional
			AllExampleActivity
			SkipUntilExampleActivity
			...
		connectable
			ConnectableExampleActivity
			...
		converting
			ConvertingActivity
			...
		creating
			CreateExampleActivity
			DeferExampleActivity
			FromExampleActivity
			JustExampleActivity
			...
		errorhanding
			CatchExampleActivity
			RetryExampleActivity
			...
		filtering
			FilterExampleActivity
			DebounceExampleActivity
			DistinctExampleActivity
			...
		mathematicalandaggregate
			AverageExampleActivity
			CountExampleActivity
			MaxExampleActivity
			ReduceExampleActivity
			...
		transforming
			BufferExampleActivity
			FlatMapExampleActivity
			MapExampleActivity
			GroupByExampleActivity
			...
		utility
			DelayExampleActivity
			TimeoutExampleActivity
			...

Operators :

  • 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

TODO

  • Many examples are to be added

Best Practices

Contact - Let's become friend

Contributing to RxJava 2 Android Samples

Just make pull request. You are in!

=======

About

RxJava2 Android Sample

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages