android-viewmodel▌
new-silvermoon/awesome-android-agent-skills · updated Apr 8, 2026
Use ViewModel to hold state and business logic. It must outlive configuration changes.
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.
2. One-Off Events (SharedFlow)
- What: Transient events like "Show Toast", "Navigate to Screen", "Show Snackbar".
- Type:
SharedFlow<UiEvent>. - Configuration: Must use
replay = 0to prevent events from re-triggering on screen rotation.private val _uiEvent = MutableSharedFlow<UiEvent>(replay = 0) val uiEvent: SharedFlow<UiEvent> = _uiEvent.asSharedFlow() - Sending: Use
.emit(event)(suspend) or.tryEmit(event).
3. Collecting in UI
- Compose: Use
collectAsStateWithLifecycle()forStateFlow.
Forval state by viewModel.uiState.collectAsStateWithLifecycle()SharedFlow, useLaunchedEffectwithLocalLifecycleOwner. - Views (XML): Use
repeatOnLifecycle(Lifecycle.State.STARTED)within a coroutine.
4. Scope
- Use
viewModelScopefor all coroutines started by the ViewModel. - Ideally, specific operations should be delegated to UseCases or Repositories.
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.6★★★★★67 reviews- ★★★★★Alexander Malhotra· Dec 28, 2024
Solid pick for teams standardizing on skills: android-viewmodel is focused, and the summary matches what you get after install.
- ★★★★★Luis Srinivasan· Dec 24, 2024
android-viewmodel reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Naina Johnson· Dec 24, 2024
Keeps context tight: android-viewmodel is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Kaira Park· Dec 4, 2024
I recommend android-viewmodel for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Oshnikdeep· Nov 27, 2024
android-viewmodel reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Kwame Gill· Nov 23, 2024
Solid pick for teams standardizing on skills: android-viewmodel is focused, and the summary matches what you get after install.
- ★★★★★William Chawla· Nov 23, 2024
Useful defaults in android-viewmodel — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Alexander Johnson· Nov 15, 2024
android-viewmodel has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Advait Desai· Nov 15, 2024
Registry listing for android-viewmodel matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Kiara Taylor· Nov 11, 2024
android-viewmodel is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
showing 1-10 of 67