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.