Consuming flows safely in Jetpack Compose

<p>Collecting flows in a lifecycle-aware manner is the&nbsp;<a href="https://developer.android.com/topic/architecture/ui-layer#consume-ui-state" rel="noopener ugc nofollow" target="_blank">recommended way</a>&nbsp;to collect flows on Android. If you&rsquo;re building an Android app with Jetpack Compose, use the&nbsp;<code>collectAsStateWithLifecycle</code>&nbsp;API to collect flows in a lifecycle-aware manner from your UI.</p> <p><code>collectAsStateWithLifecycle</code>&nbsp;allows your app to save app resources when not needed, such as when the app is in the background. Keeping resources alive unnecessarily can impact the user&rsquo;s device health. Such resources may include firebase queries, location or network updates, and database connections.</p> <p>Keep reading to know more about this API, why you should collect in a lifecycle-aware manner, and how it compares to the&nbsp;<code>collectAsState</code>&nbsp;API.</p> <p><a href="https://medium.com/androiddevelopers/consuming-flows-safely-in-jetpack-compose-cde014d0d5a3"><strong>Website</strong></a></p>