AGENT SKILL
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)
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 67
- Forks
- 24
01 前言 Front Matter
- name
- android-legacy-state
- description
- 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)
02 资源文件 3
- 参考文档evals/evals.json27.2 KB
- 参考文档references/tooling.md2.9 KB
- 参考文档references/versions.md18.9 KB
03 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
StateFlowexclusively. - Legacy: If using LiveData, observe with
viewLifecycleOwner(Fragment), NOTthis.
Anti-Patterns
- No launchWhenStarted/Resumed: Deprecated. Use repeatOnLifecycle instead.
- No observe(this) in Fragments: Use viewLifecycleOwner to prevent lifecycle leaks.