android-state
/android-state
Configure ViewModel state emission with StateFlow, SharedFlow, and sealed UiState classes in Android. Use for state modeling and sharing policies; defer generic lifecycle collection, navigation-event plumbing, Hilt injection, test code, and configuration-change recipes to their specific skills.
- Author
- HoangNguyen0403 ↗
- Repository
- agent-skills-standard ↗
- Licence
- MIT
- Last repository change
- 22.10.2026
Assessment and security
- Files in this package
- 3
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 22.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Configure ViewModel state emission with StateFlow, SharedFlow, and sealed UiState classes in Android. Use for state modeling and sharing policies; defer generic lifecycle collection, navigation-event plumbing, Hilt injection, test code, and configuration-change recipes to their specific skills.
Original author description
Configure ViewModel state emission with StateFlow, SharedFlow, and sealed UiState classes in Android. Use for state modeling and sharing policies; defer generic lifecycle collection, navigation-event plumbing, Hilt injection, test code, and configuration-change recipes to their specific skills.
How it works
- Priority: P0 (CRITICAL)
- 1. Structure ViewModel
- 2. Define UI State (LCE Pattern)
- 3. Collect State Lifecycle-Safely
- Anti-Patterns
- Verification
- References
SKILL.md preview
---
name: android-state
description: Configure ViewModel state emission with StateFlow, SharedFlow, and sealed UiState classes in Android. Use for state modeling and sharing policies; defer generic lifecycle collection, navigation-event plumbing, Hilt injection, test code, and configuration-change recipes to their specific skills.
metadata:
triggers:
files:
- '**/*ViewModel.kt'
- '**/*UiState.kt'
keywords:
- viewmodel
- stateflow
- livedata
- uistate
- MutableStateFlow
- collectAsState
- viewModelScope
- UiState
---
# Android State Management
## **Priority: P0 (CRITICAL)**
## 1. Structure ViewModel
- Expose ONE `StateFlow<UiState>` via `.asStateFlow()`.
- Use `viewModelScope` for all coroutines.
- Trigger initial load in `init` block.
See [templates](references/implementation.md) for ViewModel and UiState examples.
## 2. Define UI State (LCE Pattern)
- Use sealed interface with Loading, Content, Error variants.
- Mark data classes `@Immutable`.
See [templates](references/implementation.md) for sealed UiState pattern.
## 3. Collect State Lifecycle-Safely
- Use `collectAsStateWithLifecycle()` in Compose.
- Use `SharingStarted.WhileSubscribed(5000)` for shared resources.
## Anti-Patterns
- **No LiveData for New Code**: Use StateFlow — lifecycle-safe and Compose-compatible.
- **No Public MutableStateFlow**: Expose only `.asStateFlow()` to consumers.
- **No Context in ViewModel**: Leaks Activity. Use Application context if truly needed.
## Verification
- [ ] Each ViewModel exposes exactly one `StateFlow<UiState>`.
- [ ] UiState is a sealed interface with Loading, Content, Error variants.
- [ ] UI collects with `collectAsStateWithLifecycle()`.
- [ ] `./gradlew test` passes for ViewModel tests.
## References
- [Templates](references/implementation.md)
Files in this package (3)
- SKILL.md 2 KB
- evals/evals.json 3 KB
- references/implementation.md 2 KB
Versions
The database has no other skills named android-state.
Database snapshot: 13.11.2026 · package version 58111fa59306 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 95kotlin-flows
Use when working with Flow, StateFlow, SharedFlow, or Channel in Kotlin — including cold vs hot stream decisions, operator chains, lifecycle-safe collection, UI state management, callback bridging, or Channel migration in Android or KMP projects. - 90Android Architecture
Structure an Android app cleanly: MVVM/MVI, ViewModel, StateFlow, repositories, navigation and optional DI. Use when a project grows beyond one screen or the user asks for a maintainable structure. - 100kotlin-android
Use when building or fixing a native Android app in Kotlin and Jetpack Compose on the UDF layered architecture — ViewModel/StateFlow, Hilt, Room, Retrofit, coroutines, type-safe Navigation, and the Gradle/AGP surface. NOT shared Android and iOS UI from one Kotlin codebase (that… - 100android-architecture-components-mvvm
Use this skill when structuring production Android applications using ViewModel, StateFlow, LiveData, and Clean Architecture. - 100jetpack-compose-expert
Use when working in a native Android Jetpack Compose project - build.gradle.kts with androidx.compose BOM or org.jetbrains.kotlin.plugin.compose, *.kt files containing @Composable functions, MainActivity with setContent, or mentions of Compose, Material 3, recomposition,… - 100android-architecture
Apply Clean Architecture layering, modularization, and Unidirectional Data Flow in Android projects. Use when setting up project structure, placing code in layers, configuring feature/core modules, or implementing UDF patterns; defer Compose state and ViewModel/StateFlow…