mcpbeat

Android State

hoangnguyen0403/android-state

Configure ViewModel state emission with StateFlow, SharedFlow, and sealed UiState classes in Android. Use for state modeling and sharing policies; defer generic lifecycle collection, navigation-event plumbing, Hilt injection, test code, and configuration-change recipes to their specific skills.

2k tokens
context cost
the whole folder, loaded on every use
3
files
instructions only
0
copies elsewhere
how many repositories repackaged it
536
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/HoangNguyen0403/agent-skills-standard --skill android-state

What comes with it

4 989 bytes besides the instruction
evals/evals.json
references/implementation.md

The instruction itself

8 sections, as written by the author

Android State Management

Priority: P0 (CRITICAL)

1. Structure ViewModel

  • Expose ONE StateFlow<UiState> via .asStateFlow().
  • Use viewModelScope for all coroutines.
  • Trigger initial load in init block.

See templates for ViewModel and UiState examples.

2. Define UI State (LCE Pattern)

  • Use sealed interface with Loading, Content, Error variants.
  • Mark data classes @Immutable.

See templates for sealed UiState pattern.

3. Collect State Lifecycle-Safely

  • Use collectAsStateWithLifecycle() in Compose.
  • Use SharingStarted.WhileSubscribed(5000) for shared resources.

Anti-Patterns

  • No LiveData for New Code: Use StateFlow — lifecycle-safe and Compose-compatible.
  • No Public MutableStateFlow: Expose only .asStateFlow() to consumers.
  • No Context in ViewModel: Leaks Activity. Use Application context if truly needed.

Verification

  • [ ] Each ViewModel exposes exactly one StateFlow<UiState>.
  • [ ] UiState is a sealed interface with Loading, Content, Error variants.
  • [ ] UI collects with collectAsStateWithLifecycle().
  • [ ] ./gradlew test passes for ViewModel tests.

References

  • Templates

How to use it

Copy the folder

Take hoangnguyen0403/android-state from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.