--

That's correct, the ViewModel caches the data so it stays available for the Activity, or a new instance of the Activity in case it gets re-created.

As soon as you stop collecting a Flow that did not complete (StateFlow and SharedFlow never complete), it restarts from scratch on the next collection and this will cause the same data to be loaded again.

--

--

Christophe Beyls
Christophe Beyls

Written by Christophe Beyls

Android developer from Belgium, blogging about advanced programming topics.

No responses yet