Agent-skills-standard android-legacy-state

Integrate State with Views using Coroutines and Lifecycle on Android. Use when managing state with ViewModels and Lifecycle-aware coroutines in Android. (triggers: **/*Fragment.kt, **/*Activity.kt, repeatOnLifecycle, launchWhenStarted)

install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/android/android-legacy-state" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-android-legacy-state && rm -rf "$T"
manifest: skills/android/android-legacy-state/SKILL.md
source content

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 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

  • No launchWhenStarted/Resumed: Deprecated. Use repeatOnLifecycle instead.
  • No observe(this) in Fragments: Use viewLifecycleOwner to prevent lifecycle leaks.

References