CtrlK
BlogDocsLog inGet started
Tessl Logo

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.

70

Quality

86%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Passed

No findings from the security scan

SKILL.md
Quality
Evals
Security

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

Repository
HoangNguyen0403/agent-skills-standard
Last updated
First committed

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.