UI state & unidirectional data flow
Hoisting state, surviving config changes (ViewModel/SavedStateHandle, @StateObject), and MVVM/MVI patterns. State that outlives the view is the core mobile skill.
The mental model
A well-run kitchen has one source of truth for every order: the ticket rail. Waiters do not each keep their own mental list of what table 7 ordered — they read the rail, and when something changes, they write to the rail. If every waiter kept their own copy, you would get two plates for one order and a table that never gets its dessert. UI state management is the ticket rail for your screen: there is one authoritative copy of "what the screen should show", the UI *reads* from it, and events *write* to it. Data flows one way — down to the view, and back up as events — which is why the discipline is called unidirectional data flow (UDF).
The reason mobile forces this discipline harder than the web is that your view is disposable (recreated on rotation) and your process is mortal (killed in the background). If state lives *inside* the view — a field on the fragment, an @State scattered across subviews — it dies with the view. So the mobile rule becomes: **state that matters must outlive the view that displays it.** You *hoist* it up into a holder (a ViewModel on Android, an @Observable/ObservableObject on iOS) that survives configuration changes, and you back the survive-anything parts with SavedStateHandle/scene storage so they survive process death too.
Two patterns formalise this. MVVM (Model–View–ViewModel): the ViewModel exposes observable state and the view renders it and forwards events. MVI (Model–View–Intent): the same, but the entire screen state is a single immutable object and every change is an explicit intent that produces a new state — one state object in, one state object out, which makes the screen a pure function of state and trivially testable.
The unifying idea, and the thing interviewers actually grade: the view is a projection of state, not the owner of it. Get the ownership right and rotation, process death, and "why is the UI showing stale data" all stop being special cases — they are just "re-project the current state".
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision