DEV Community

loizenai
loizenai

Posted on

How to integrate RxJava into Android App with examples

How to integrate RxJava into Android App with examples

https://grokonez.com/android/how-to-integrate-rxjava-into-android-app-with-examples

In this tutorial, grokonez.com shows you way to integrate RxJava 2 into Android App, along with 3 simple examples that apply RxJava:

  • CompoundButton (Switch) updates TextView
  • Update TextView when text length in EditText changes
  • Reactive Text search

Set up Android environment

We use Android Studio (installer from https://developer.android.com/studio/) for development. It doesn't support RxJava, so we need to add RxJava 2 library.

Add RxJava 2 dependencies

Open app/build.gradle file, add RxJava and RxBinding wrappers for UI:


dependencies {
    ...

    implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
}
Add Java 8 lambdas
We also need to add Java 8 to the configuration to use lambdas:
android {
    ...
    defaultConfig {
        ...
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    ...
}

https://grokonez.com/android/how-to-integrate-rxjava-into-android-app-with-examples

Top comments (0)