Android Concurrency Standards
Priority: P0
Implementation Guidelines
Structured Concurrency
- Scopes: Always use
viewModelScope(VM) orlifecycleScope(Activity/Fragment). - Dispatchers: INJECT Dispatchers (
DispatcherProvider) for testability. Do not hardcodeDispatchers.IO.
Flow usage
- Cold Streams: Use
Flowfor data streams. - Hot Streams: Use
StateFlow(State) orSharedFlow(Events). - Collection: Use
collectAsStateWithLifecycle()(Compose) orrepeatOnLifecycle(Views).
Anti-Patterns
- No GlobalScope: Use viewModelScope or lifecycleScope — never GlobalScope.
- No async/await by default: Prefer simple suspend functions; async only for parallel calls.