android-viewmodel

Implement Android ViewModels with StateFlow for UI state and SharedFlow for events.

1|Updated Feb 20, 2026
One-click install
npx skills add https://github.com/escorponox/musiharmony --skill android-viewmodel-escorponox
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: android-viewmodel
Source: https://github.com/escorponox/musiharmony/tree/main/.claude/skills/android-viewmodel
Command: npx skills add https://github.com/escorponox/musiharmony --skill android-viewmodel-escorponox

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides clear guidance on implementing Android ViewModels, focusing on modern best practices for managing UI state and handling one-off events effectively.

Core Features & Use Cases

  • StateFlow for UI State: Manages persistent UI data that survives configuration changes.
  • SharedFlow for Events: Handles transient UI events like navigation or snackbars without replaying them.
  • Lifecycle-Aware Collection: Ensures data collection is tied to the UI's lifecycle for efficiency and correctness.
  • Use Case: When building an Android app, use this Skill's patterns to ensure your UI state is always up-to-date and that user interactions trigger appropriate, non-repeating feedback.

Quick Start

Implement the provided StateFlow and SharedFlow patterns within your Android ViewModel to manage UI state and events.

Frequently Asked Questions about android-viewmodel

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage Android UI state with StateFlow and SharedFlow in a ViewModel?▼

To manage Android UI state, use StateFlow for persistent UI data and SharedFlow for transient events. This pattern ensures configuration changes survive and one-off events avoid replaying in the ViewModel.

What is the best way to handle one-off events in Android Jetpack Compose?▼

The best way to handle one-off events in Android Jetpack Compose is emitting them via SharedFlow. This prevents transient UI events like navigation or snackbars from replaying when the UI recomposes.

How do I collect ViewModel StateFlow with lifecycle awareness in Android?▼

To collect ViewModel StateFlow with lifecycle awareness, tie data collection to the UI's lifecycle. This ensures efficient state updates and correct processing only when the Android UI is active.

When should I use StateFlow instead of SharedFlow for Android state management?▼

Use StateFlow instead of SharedFlow for Android state management when you need persistent UI data that survives configuration changes. SharedFlow is reserved for transient, one-off UI events.

Why does my Android ViewModel emit duplicate UI events after configuration changes?▼

Your Android ViewModel emits duplicate UI events because state is not separated by flow type. Using SharedFlow for one-off events prevents transient UI feedback from replaying upon collection.