# Swampy Refactor: Converting Otto Bus to Flows

DevFeed: [Swampy Refactor: Converting Otto Bus to Flows](<https://devfeed.tech/articles/swampy-refactor-converting-otto-bus-to-flows-32080.md>)

Original publisher: [Read original article](<https://www.maiatoday.net/p/swampy-refactor-converting-otto-bus-to-flows/>)

Published: 2023-07-17T17:18:36Z

Content type: tutorial

Language: en

Sources: [maiatoday](<https://devfeed.tech/sources/maiatoday.md>)

Topics: [migration](<https://devfeed.tech/topics/migration.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [deprecated](<https://devfeed.tech/topics/deprecated.md>), [Code](<https://devfeed.tech/topics/code.md>), [RxJava](<https://devfeed.tech/topics/rxjava.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Git](<https://devfeed.tech/topics/git.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [flow](<https://devfeed.tech/tags/flow.md>), [git](<https://devfeed.tech/tags/git.md>), [migration](<https://devfeed.tech/tags/migration.md>), [otto-bus](<https://devfeed.tech/tags/otto-bus.md>), [refactor](<https://devfeed.tech/tags/refactor.md>), [rxjava](<https://devfeed.tech/tags/rxjava.md>), [swampy](<https://devfeed.tech/tags/swampy.md>)

## AI overview

This tutorial explains how to migrate an Android application from the deprecated Otto Bus event bus to Kotlin Flow. It presents an incremental, event-by-event process and notes that the work may require architectural refactoring, dependency-injection changes, and testing.

## Source excerpt

The story starts I was wandering around my day job's code base and I happened on a time capsule - a pristine Java Activity studded with semi-colons, a snapshot of how we built things in 2014. All the member variables started with m and there was plenty of logic to update the screen and dictate actions. Despite being old, it's still used every day by users. Why would I change it? The Bus disappears Well, it got its data from a subscription to the Otto Bus. Otto Bus was deprecated in 2016. A blog post suggested migrating to RxJava, but since our code base standard now involves coroutines, Flows, and in some cases, LiveData, I decided to remove deprecated libraries and complete the partial migrations we started some time ago. This blog post summarizes how to migrate from Otto Bus to Flow. I've also created a Git repo with a simplified example that uses Otto Bus, with a conversion to Flow in the commit history. Check out the otto-bus tag for the working Otto Bus version and the flow tag for the converted Flow version. I am sparing you the Java to Kotlin conversions. This toy app lets you tap on the 8 ball for a message. It uses Otto Bus to notify the 8 Ball that a new message is needed as well as when a new message is available. How to tackle the migration - step by step Here are the basic steps for this kind of migration: Pick one event Find All the producers of this event (hopefully, there is only one but don't count on it) Replace with compatible functionality. We'll look at how to choose compatible functionality in the next section. Things will be broken. Find all subscribers of this event by looking for @Subscribe annotations. Replace with a matching access mechanism. Things should work at this point. Test that everything that used this one event still works Repeat with the next event until there are no events left to migrate Remove the Otto bus and it's dependencies Celebrate! Of course this looks deceptively simple. As simple as it is to add otto bus to a code ba