Agent skill

Android Legacy State

Standards for State integration with Views using Coroutines and Lifecycle

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/legacy-state

Metadata

Additional technical details for this skill

labels
android state views lifecycle
triggers
{
    "files": [
        "**/*Fragment.kt",
        "**/*Activity.kt"
    ],
    "keywords": [
        "repeatOnLifecycle",
        "launchWhenStarted"
    ]
}

SKILL.md

Android Legacy State Standards

Priority: P1

Implementation Guidelines

Flow Consumption

  • Rule: ALWAYS use repeatOnLifecycle(Lifecycle.State.STARTED) to collect flows in Views.
  • Why: Prevents crashes (collecting while view is destroyed) and saves resources (stops collecting in background).

LiveData vs Flow

  • New Code: Use StateFlow exclusively.
  • Legacy: If using LiveData, observe with viewLifecycleOwner (Fragment), NOT this.

Anti-Patterns

  • launchWhenX: **Deprecated**: Use repeatOnLifecycle.
  • observe(this): **Leak Risk**: Use viewLifecycleOwner in Fragments.

References

  • Flow Consumption Template

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results