Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
mobile ruleP1stack specificStack: android
androidviewmodellifecyclestate
Keep UI state in a ViewModel that survives config changes
State stored in the Activity/Fragment is lost on rotation; hoist it into a ViewModel so it survives configuration changes.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codekotlin
| 1 | class MainActivity { var items = listOf<X>() } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codekotlin
| 1 | class MainViewModel: ViewModel() { val items = MutableStateFlow<List<X>>(emptyList()) } |
Explanation (EN)
Objašnjenje (HR)