Room + Kotlin Flow — The modern Android architecture for location-aware apps

The first Android demo video from Google

How to handle location updates?

Almost there…

The “event bus” design of LocalBroadcastManager is deprecated because it violates Android architecture principles

LocalBroadcastManager is an application-wide event bus and embraces layer violations in your app: any component may listen events from any other. You can replace usage of LocalBroadcastManager with other implementation of observable pattern, depending on your use case suitable options may be LiveData or reactive streams.

It inherits unnecessary use-case limitations of system BroadcastManager; developers have to use Intent even though objects live in only one process and never leave it. For this same reason, it doesn’t follow feature-wise BroadcastManager.

The solution — Room + Kotlin Flow

Our UI can observe changes from the repository (Room) using Kotlin Flow
The Service inserts new locations into Room, and the Activity observes them via Kotlin Flow!

Closing thoughts

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store