Kotlin callbackFlow: A lightweight architecture for location-aware Android apps

Database buyer’s remorse

The legacy approach to sharing locations based on the deprecated LocalBroadcastManager
My initial solution —the Service inserts new locations in Room, and our UI can observe changes from Room using Kotlin Flow

The solution — callbackFlow

A pure Kotlin Flow-based solution is lightweight and allows all app components to be observers
In the while-in-use-location example, the user can start and stop location updates from the UI
The Service observes location updates via Flow to update an ongoing notification
SharedLocationManager uses a callbackFlow to manage location updates which is observed by the Service and Activity

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