Agent-skills-standard android-state
Configure ViewModel state emission with StateFlow, sealed UiState classes, and lifecycle-safe collection in Android. Use when working with ViewModel files, UiState sealed classes, MutableStateFlow, collectAsStateWithLifecycle, or exposing state from ViewModels. (triggers: **/*ViewModel.kt, **/*UiState.kt, viewmodel, stateflow, livedata, uistate, MutableStateFlow, collectAsState, viewModelScope, UiState)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/android/android-state" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-android-state && rm -rf "$T"
manifest:
skills/android/android-state/SKILL.mdsource content
Android State Management
Priority: P0
1. Structure ViewModel
- Expose ONE
viaStateFlow<UiState>
..asStateFlow() - Use
for all coroutines.viewModelScope - Trigger initial load in
block.init
See templates 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 for sealed UiState pattern.
3. Collect State Lifecycle-Safely
- Use
in Compose.collectAsStateWithLifecycle() - Use
for shared resources.SharingStarted.WhileSubscribed(5000)
Anti-Patterns
- No LiveData for New Code: Use StateFlow — lifecycle-safe and Compose-compatible.
- No Public MutableStateFlow: Expose only
to consumers..asStateFlow() - No Context in ViewModel: Leaks Activity. Use Application context if truly needed.