Sitemap

Converting LiveData to Flow: More lessons learned

3 min readJun 23, 2021

--

Press enter or click to view image in full size
Photo: Buzz Andersen from Unsplash

If the LiveData becomes inactive (LiveData.onInactive) while the flow has not completed, the flow collection will be cancelled after timeoutInMs milliseconds unless the LiveData becomes active again before that timeout (to gracefully handle cases like Activity rotation).

After a cancellation, if the [LiveData] becomes active again, the upstream flow collection will be re-executed.

An exception to this behavior is that observers also receive an update when they change from an inactive to an active state. (From LiveData Overview)

--

--

Chao Zhang
Chao Zhang

Written by Chao Zhang

Vibe Coding & Orchestrating @ Instacart