Unify Android EventBus and RxJava with Kotlin Flow

Mixing EventBus, RxJava, and Kotlin Flow in Android codebases creates memory leaks and GC pressure from stream wrapping. Operator translation and lifecycle mismatches drive engineering debt.
Why it matters
Fragmented reactive architectures in Android directly degrade application stability and developer velocity. When legacy modules rely on GreenRobot EventBus, data layers expose RxJava streams, and presentation logic adopts Kotlin Flow, engineers pay a hidden tax on every feature. Constant conversions between Observable.asFlow() and flow.asLiveData() generate garbage collection pressure and chain-allocation costs that accumulate during user sessions. More critically, mismatched lifecycle models lead to undisposed Rx subscriptions and unsafe Flow collection scopes, producing memory leaks and production crashes. In high-scale codebases, this fragmentation is not merely stylistic debt; it is an active reliability defect that slows debugging and complicates onboarding.
What changed
Kotlin Flow combined with Kotlin Coroutines has become the definitive reactive standard for Kotlin-first Android ecosystems. The article maps operator counterparts across paradigms, clarifying that Flow uses suspending pull-based backpressure rather than RxJava explicit strategy contracts such as DROP or LATEST. It distinguishes cold streams, which execute lazily per collector and restart logic for each subscriber, from hot streams that emit regardless of active observers. Key operator mappings include flatMapLatest, flatMapConcat, and combine for merging and flattening nested streams. Terminal operators like collect() trigger upstream demand propagation, while cancellation signals travel upstream to tear down producers and intermediate buffers safely without manual disposal.
What to watch
Teams should freeze new RxJava and EventBus adoption immediately. Migration priority should target high-leak surfaces first: replace unsafe lifecycle subscriptions with lifecycle-aware coroutine scopes such as viewModelScope, convert Observable chains to Flow using equivalent transformational and filtering operators, and remove EventBus decoupling in favor of explicit data flow through ViewModels and repositories. Monitor carefully for backpressure behavior changes when moving from Flowable explicit strategies to Flow suspension semantics. Expect measurable reductions in ANR rates and memory churn within one release cycle after core streams are unified under a single paradigm.
Interview question
Which migration step should teams prioritize first to reduce memory leaks when unifying Android reactive streams?
- a.Add explicit DROP or LATEST backpressure strategies to every Kotlin Flow collector
- b.Convert EventBus subscribers into RxJava Observables as an incremental interim step
- c.Map all RxJava operators to Kotlin Flow equivalents before touching subscriptions
- d.Replace unsafe lifecycle subscriptions with lifecycle-aware coroutine scopes like viewModelScopeCorrect
Why? this is the answer
The card identifies replacing unsafe lifecycle subscriptions with scopes such as viewModelScope as the top priority for high-leak surfaces. Mapping operators first does not fix the lifecycle mismatches that directly cause undisposed subscriptions and memory leaks.
Just read this? Test yourself on what you have been reading.
Read the original → proandroiddev.com
- #android
- #kotlin-flow
- #rxjava
- #eventbus
- #migration
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles