android-viewmodel
Android ViewModel & State Management
Instructions
Use ViewModel to hold state and business logic. It must outlive configuration changes.
1. UI State (StateFlow)
- What: Represents the persistent state of the UI (e.g.,
Loading,Success(data),Error). - Type:
StateFlow<UiState>. - Initialization: Must have an initial value.
- Exposure: Expose as a read-only
StateFlowbacking a privateMutableStateFlow.private val _uiState = MutableStateFlow<UiState>(UiState.Loading) val uiState: StateFlow<UiState> = _uiState.asStateFlow() - Updates: Update state using
.update { oldState -> ... }for thread safety.
More from new-silvermoon/awesome-android-skills
compose-ui
Best practices for building UI with Jetpack Compose, focusing on state hoisting, detailed performance optimizations, and theming. Use this when writing or refactoring Composable functions.
3android-testing
Comprehensive testing strategy involving Unit, Integration, Hilt, and Screenshot tests.
2gradle-build-performance
Debug and optimize Android/Gradle build performance. Use when builds are slow, investigating CI/CD performance, analyzing build scans, or identifying compilation bottlenecks.
2android-coroutines
Authoritative rules and patterns for production-quality Kotlin Coroutines onto Android. Covers structured concurrency, lifecycle integration, and reactive streams.
2compose-navigation
Implement navigation in Jetpack Compose using Navigation Compose. Use when asked to set up navigation, pass arguments between screens, handle deep links, or structure multi-screen apps.
2xml-to-compose-migration
Convert Android XML layouts to Jetpack Compose. Use when asked to migrate Views to Compose, convert XML to Composables, or modernize UI from View system to Compose.
2