Pick the fix
A team moves its ViewModels to StateFlow and the screen now updates while it's in the background. What did they lose?
Hint 1 of 1
What did LiveData's observe(owner) do that collect doesn't?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Lifecycle awareness: they must collect with repeatOnLifecycle or collectAsStateWithLifecycle
Correct. LiveData stopped dispatching below STARTED; StateFlow needs a lifecycle-aware collector.
Why not the others?
- B Thread safety: StateFlow isn't thread-safe. StateFlow is safe to update from any thread.
- C The initial value. StateFlow requires one; LiveData is the one that may not have it.
- D Nothing; StateFlow stops in the background on its own. It doesn't know about lifecycles at all.