Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Reactive Programming

Android Reactive Programming

Reactive Android at Geeky base (29/04/2017)

WeRockStar

April 29, 2017
Tweet

More Decks by WeRockStar

Other Decks in Programming

Transcript

  1. REACTIVE PROGRAMMING (ANDROID) COURSE OUTLINE ▸ What is Reactive Programming

    ▸ What is Rx ▸ Reactive manifesto ▸ History of Rx ▸ RxJava1, RxJava 2 ▸ Key types ▸ Operators ▸ RxBinding ▸ Retrofit ▸ Concurrency ▸ Multiple source ▸ Error handling ▸ Backpressure
  2. Reactive programming is a general programming term that is focused

    on reacting to changes, such as data values or events Ben Christensen REACTIVE PROGRAMMING (ANDROID) @werockstar
  3. Reactive programming is an asynchronous programming paradigm oriented around data

    streams and the propagation of change. Wikipedia REACTIVE PROGRAMMING (ANDROID) @werockstar
  4. ReactiveX (Rx) is a library for composing asynchronous and event-based

    programs by using observable sequences. ReactiveX REACTIVE PROGRAMMING (ANDROID) @werockstar
  5. Reactive Programming It hard to definition of What is Reactive

    Programming Characteristics of Reactive programming - Propagate for change - Data streams (Everything is Stream) - React to change
  6. ▸ Responsive - timely react to user ▸ Resilient -

    recover from failure or error ▸ Elastic - react by increasing or decreasing the resources allocate ▸ Message Driven - react to events or messages REACTIVE PROGRAMMING (ANDROID) REACTIVE MANIFESTO @werockstar
  7. Reactive Programming (RP) = Over time Functional Reactive Programming (FRP)

    = Continuous time REACTIVE PROGRAMMING (ANDROID) @werockstar
  8. Reactive Programming (RP) = Productivity for Developer at component level,

    internal level and data flow management. Reactive System = Productivity for DevOps at system level REACTIVE PROGRAMMING (ANDROID) @werockstar
  9. HISTORY ▸ Original by Microsoft - Erik Meijer ▸ 2009

    - Rx.NET v.1.0.0 ▸ 2010 - RxJS ▸ 2012 - Ported from Rx.Net to RxJava by Netflix ▸ 2014 - Release RxJava 1.0 ▸ 2016 - Release RxJava 2.0 on top of the Reactive-Streams specification REACTIVE PROGRAMMING (ANDROID) @werockstar
  10. RxJava1 REACTIVE PROGRAMMING (ANDROID) ▸ June 1, 2017 - feature

    freeze (no new operators), only bug fixes ▸ March 31, 2018 - end of life, no further development @werockstar
  11. RxJava2 - Major changes REACTIVE PROGRAMMING (ANDROID) ▸ Reactive Streams

    ▸ Changing package from rx. to io.reactivex ▸ Backpressure (Flowable) ▸ * Bye. Nulls @werockstar
  12. Key Types REACTIVE PROGRAMMING (ANDROID) ▸ Observable, Observer ▸ Flowable,

    Subscriber ▸ Single, Completable, Maybe ▸ Disposable (Subscription) ▸ Subject @werockstar
  13. REACTIVE PROGRAMMING (ANDROID) Observable is represents the stream of data

    and can be subscribed to by an Observer @werockstar
  14. REACTIVE PROGRAMMING (ANDROID) Observable.just(“Reactive Android") .subscribe(new Observer<String>() { @Override public

    void onSubscribe(Disposable d) { } @Override public void onNext(String s) { } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }) @werockstar Observer
  15. Concurrency ▸ subscribeOn() - Specify the Scheduler on which an

    Observable will operate ▸ observeOn() - Observable to send notifications to observers on a specified Scheduler REACTIVE PROGRAMMING (ANDROID) @werockstar
  16. Multiple source ▸ flatMap - transform the items emitted by

    an Observable into Observables, then flatten this into a single Observable ▸ concatMap - transform the items emitted by an Observable into Observables, then flatten this into a single Observable (sequentially) REACTIVE PROGRAMMING (ANDROID) @werockstar
  17. Error handling ▸ onErrorReturn() - discards it and replaces it

    with a fixed value. ▸ onErrorResumeNext() - replaces error notification with another stream. ▸ onErrorReturnItem() - discards it and replaces it with a fixed value. ▸ retry() - resubscribe to it if it calls onError, hoping that it will keep producing normal events rather than failures. ▸ retryWhen() - if Observable emits an error, pass that error to another Observable to determine whether to resubscribe to the source. REACTIVE PROGRAMMING (ANDROID) @werockstar
  18. Backpressure ▸ RxJava1 late for design support ▸ RxJava2 fully

    support (Flowable) REACTIVE PROGRAMMING (ANDROID) @werockstar