> android-legacy-state

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

fetch
$curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/android-legacy-state?format=md"
SKILL.mdandroid-legacy-state

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

┌ stats

installs/wk0
░░░░░░░░░░
github stars341
██████████
first seenMar 17, 2026
└────────────

┌ repo

HoangNguyen0403/agent-skills-standard
by HoangNguyen0403
└────────────

┌ tags

└────────────