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

Vietnam MobileDay GoLive 2020

Vietnam MobileDay GoLive 2020

## Reactive Programming in Kotlin/Android

- What is reactive programming?
- How do we realize reactive programming concepts with Kotlin/Android
- Some common patterns we use in Android development with reactive programming

Toan Tran

August 17, 2020
Tweet

More Decks by Toan Tran

Other Decks in Technology

Transcript

  1. About speaker Hello! I’m Toan VP, Mobile @Lazada (check out

    our opening positions!) https://toan.mobi toantran-ea toan_mobi
  2. Reactive Programming in Kotlin|Android 1. The ultimate goal of app

    development. 2. Introducing Reactive Programming. 3. Realize RP with Kotlin in Android. 4. Some common patterns we may use daily. 5. Key-takeaways.
  3. 1. Introducing Reactive Programming 1. A programming paradigm. 2. Based

    on 3 pillars: ◦ Data streams. ◦ Asynchronous processing. ◦ Functional programming.
  4. 1. Introducing Reactive Programming Reactive Programming vs … Val data

    = getDataFromStream() If (data is matched condition) { ui.display() } getDataFromStream(). .filter( condition ) .subscribe { ui.display() }
  5. 1. Introducing Reactive Programming Reactive Programming vs … Val remote

    = getDataFromStream() // blocking call Val local = readFromLocalDB() // blocking call If (remote is matched condition 1 AND local matched condition 2 ) { ui.display() } getDataFromStream(). concat(readFromLocalDB) .filter( condition1 AND condition 2 ) .subscribe { ui.display() }
  6. 1. Introducing Reactive Programming Reactive Programming vs … Callback<Remote> remote

    = getDataFromStream() Callback<Local> local = readFromLocalDB() remote.execute(THREAD_IO).onResult { res1 -> local.excecute(THREAD_IO).onResult {res2 -> if (condition 1 and condition 2) { runOnnUIThread { ui.display() } } } } getDataFromStream(). concat(readFromLocalDB) .subcribeOn(THREAD_IO) .filter( condition1 AND condition 2 ) .observerOn(UI_THREAD) .subscribe { ui.display() }
  7. 3. Realize RP in Kotlin/Android • http://reactivex.io/ • RxJava, RxJS,

    RxSwift, etc • Early adopted by big names: Netflix, Microsoft, GitHub, SoundCloud, etc
  8. 3. Realize RP in Kotlin/Android RxJava: - Create - Combine

    - Subscribe RxAndroid: - Android threading
  9. 5. Key takeaways 1. Reactive Programming is paradigm based on

    async stream processing with the support of functional programming. 2. Realize with ReactiveX language implementations: RxJava, RxKotlin, RxSwift, RxJS 3. Rx provided with set of common tools/pattern to solve data manipulating in an asynchronous manner.