Consuming flows safely in Jetpack Compose
<p>Collecting flows in a lifecycle-aware manner is the <a href="https://developer.android.com/topic/architecture/ui-layer#consume-ui-state" rel="noopener ugc nofollow" target="_blank">recommended way</a> to collect flows on Android. If you’re building an Android app with Jetpack Compose, use the <code>collectAsStateWithLifecycle</code> API to collect flows in a lifecycle-aware manner from your UI.</p>
<p><code>collectAsStateWithLifecycle</code> 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’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 <code>collectAsState</code> API.</p>
<p><a href="https://medium.com/androiddevelopers/consuming-flows-safely-in-jetpack-compose-cde014d0d5a3"><strong>Website</strong></a></p>