Collect the `ViewModel`'s single `StateFlow<UiState>` with the lifecycle-aware Compose API: ```kotlin @Composable fun FeedRoute(viewModel: FeedViewModel = hiltViewModel()) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() when (val state = uiState) { FeedUiState.Loading -> LoadingContent() is FeedUiState.Content -> FeedContent(items = state.items) is FeedUiState.Error -> ErrorContent( message = state.message, onRetry = viewModel::loadFeed, ) } } ``` `collectAsStateWithLifecycle...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-state --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Android State?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-state-f48114ab)More formats (shields.io, HTML) on the badges page.
Collect the `ViewModel`'s single `StateFlow<UiState>` with the lifecycle-aware
Compose API:
```kotlin
@Composable
fun FeedRoute(viewModel: FeedViewModel = hiltViewModel()) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
when (val state = uiState) {
FeedUiState.Loading -> LoadingContent()
is FeedUiState.Content -> FeedContent(items = state.items)
is FeedUiState.Error -> ErrorContent(
message = state.message,
onRetry = viewModel::loadFeed,
)
}
}
```
`collectAsStateWithLifecycle()` starts and stops collection with the UI
lifecycle, avoiding work while the screen is not active. Keep the exposed flow
read-only (`private MutableStateFlow` plus `asStateFlow()`) and render the
sealed loading/content/error state declaratively. If the flow is shared from a
costly upstream resource, configure sharing with
`SharingStarted.WhileSubscribed(5000)` so it can stop after subscribers leave.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!