Skip to content

Best-practice guide for Android ViewModels using Kotlin explicit backing fields, StateFlow state, and SharedFlow events.

CCM score
63 of 100
skills.sh installs
602
GitHub stars
1K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers UI state modeling, updating, and collection in both Compose and the XML/View system
  • Includes a StateFlow pattern for persistent screen state and a SharedFlow pattern for transient events like navigation and snackbars
  • Enforces immutable exposed APIs, update {} for state changes, and no StateFlow for navigation events
  • Designed for Kotlin 2.4+ projects, with a fallback note for Kotlin 2.3 experimental explicit backing fields

Install

$ npx -y skills add new-silvermoon/awesome-android-agent-skills --skill android-viewmodel -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Android ViewModel & State Management

Instructions

Use ViewModel to own UI state and business logic. It should survive configuration changes and expose immutable APIs.

Kotlin 2.3+

Prefer Explicit Backing Fields instead of the traditional _state/state backing property pattern.

  • Kotlin 2.3: Experimental (-Xexplicit-backing-fields)
  • Kotlin 2.4+: Stable (recommended)

Avoid creating duplicate backing properties unless targeting older Kotlin versions.


1. UI State (StateFlow)

Purpose

Represents the persistent UI state.

Examples:

  • Loading
  • Success(data)
  • Error(message)
  • Empty

Declaration

Use an explicit backing field.

val uiState: StateFlow<UiState>
    field = MutableStateFlow(UiState.Loading)

The backing field is mutable (MutableStateFlow) while consumers only see StateFlow.

Updating State

Prefer update { } for atomic updates.

_uiState.update { old ->
    old.copy(isLoading = false)
}

With explicit backing fields:

uiState.update {
    it.copy(isLoading = false)
}

You may also assign directly when appropriate.

Details

Repository
github.com/new-silvermoon/awesome-android-agent-skills
Category
Mobile Apps
First seen
Jun 3, 2026

Questions

What does the android-viewmodel skill do?

The android-viewmodel skill gives an AI coding agent best practices for building Android ViewModels with Kotlin 2.3+ Explicit Backing Fields, StateFlow for UI state, and SharedFlow for one-off events. It guides the agent to keep business logic out of Composables and to expose only immutable APIs.

How do I install the android-viewmodel skill?

Run npx -y skills add new-silvermoon/awesome-android-agent-skills --skill android-viewmodel -y in your project. After that, android-viewmodel lets your agent follow these ViewModel and state management patterns when it works on Android code.

Which skills does android-viewmodel sit alongside in Mobile Apps?

android-viewmodel is listed under Mobile Apps on Claude Marketplaces, next to vercel-react-native-skills and animate-expo. Where android-viewmodel differs is its focus on Android ViewModel state handling with StateFlow and SharedFlow rather than cross-platform or Swift work.

Who is android-viewmodel for?

android-viewmodel is for Android developers who want an agent to structure ViewModels around a single immutable UI state object. It also suits teams that collect one-off events like navigation or snackbars in Jetpack Compose or the XML view system.

More from new-silvermoon/awesome-android-agent-skills

All 17

Similar to Android Viewmodel

More Mobile Apps