Repository navigation
Use collectAsStateWithLifecycle() for lifecycle-aware state collection - #160
Conversation
|
Why collectAsStateWithLifecycle is better: https://youtu.be/0G_1XCRlpYM?si=AXb_FFz7JZbD3zR1&t=466 https://developer.android.com/develop/ui/compose/state
PR looks fine, I will double check again in android studio and merge it |
ounben
left a comment
There was a problem hiding this comment.
val recordState by recordManager.recordingState.collectAsStateWithLifecycle()
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
ounben
left a comment
There was a problem hiding this comment.
StateWithLifecycle(initialValue
What
Replaces Compose's
collectAsState()withcollectAsStateWithLifecycle()in the UI and recorder composables (15 files, mechanical change).Why
collectAsState()keeps collecting while the screen is in the background — e.g. when the user switches to another tab, opens the player from a list, or leaves the app. That keeps Room queries / view-model flows actively delivering updates and holding references longer than needed.collectAsStateWithLifecycle()pauses collection when the lifecycle drops belowSTARTEDand resumes on return, which is the recommended pattern for Compose + StateFlow.The project already depends on
androidx.lifecycle:lifecycle-runtime-compose, so no build changes are needed.Notes
Flowcollectors useinitialValue = ...(the lifecycle-aware overload's parameter name); plainStateFlowcollectors are unchanged apart from the call.AI disclosure
This PR was authored by an AI coding agent (OpenCode, running DeepSeek V4.1 Flash) under human supervision: the change, tests and description were generated by the agent and reviewed by the contributor before submission.