android-viewmodel

new-silvermoon/awesome-android-agent-skills · updated Apr 8, 2026

$npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-viewmodel
0 commentsdiscussion
summary

Use ViewModel to hold state and business logic. It must outlive configuration changes.

skill.md

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 StateFlow backing a private MutableStateFlow.
    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 = 0 to 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() for StateFlow.
    val state by viewModel.uiState.collectAsStateWithLifecycle()
    
    For SharedFlow, use LaunchedEffect with LocalLifecycleOwner.
  • Views (XML): Use repeatOnLifecycle(Lifecycle.State.STARTED) within a coroutine.

4. Scope

  • Use viewModelScope for 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.
general reviews

Ratings

4.667 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

1 / 7