CtrlK
BlogDocsLog inGet started
Tessl Logo

android-state

Configure ViewModel state emission with StateFlow, sealed UiState classes, and lifecycle-safe collection in Android. Use when working with ViewModel files, UiState sealed classes, MutableStateFlow, collectAsStateWithLifecycle, or exposing state from ViewModels. (triggers: **/*ViewModel.kt, **/*UiState.kt, viewmodel, stateflow, livedata, uistate, MutableStateFlow, collectAsState, viewModelScope, UiState)

89

Quality

86%

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

SKILL.md
Quality
Evals
Security

Android State Management

Priority: P0

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.

References

Repository
HoangNguyen0403/agent-skills-standard
Last updated
Created

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.