Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
new-silvermoon avatar

Android Viewmodel

  • 3 installs
  • 910 repo stars
  • Updated July 27, 2026
  • new-silvermoon/awesome-android-skills

Helps with ai & agent building tasks.

About

android-viewmodel is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted coding.

  • android-viewmodel
  • AI & Agent Building
  • AI-coding skill

Android Viewmodel by the numbers

  • 3 all-time installs (skills.sh)
  • Ranked #13,677 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/new-silvermoon/awesome-android-skills --skill android-viewmodel

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs3
repo stars910
Last updatedJuly 27, 2026
Repositorynew-silvermoon/awesome-android-skills

What it does

Helps with ai & agent building tasks.

Files

SKILL.mdMarkdownGitHub ↗

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.

Related skills

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.