MVI - Overview with Linked Examples
MVI
Summary
MVI, Model-View-Intent, is widely considered the standard default recommended practice for Android Jetpack Compose Apps.
It prescribes a pattern for connecting the UI and data.
Main Features
- Unidirectional Data Flow (UDF)
- Single Source of Truth (Immutable)
- Simplifies Complexity
- Predictable (therefore easier to Debug and Test)
- Pairs well with Steams and Coroutines
Brief History (Why We Changed)
Before Compose and MVI became standard, we generally used MVVM (Model-View-ViewModel) with XML Layouts. This worked quite well for smaller, simple apps, but it soon became quite error-prone and messy as things got more complex. Basically, things tended to get out of sync between the UI and the data and would often lead to impossible states. I learned this through my own experience many years ago.
From my limited research, I believe MVI was first introduced / popularized into Android development back in 2017 with Hannes Dorfmann Fragmented Podcast. Before that, it is thought to have originated late 2014 with this blog post by André Staltz as part of the Cycle.js framework.
MVI Variations
There are excellent variations of the MVI pattern - Google uses what it calls UDF. When we talk about MVI, it may not always exactly be MVI, but it is often used as a blanket term to cover variations of this basic pattern that generally follow most of the main features I mentioned above.
As with any pattern or design, dogmatic practices (following 100% without thinking) are discouraged. If something feels wrong, it probably is.
If you are an enthusiastic Android programmer, you may know about Philipp Lackner's excellent YouTube Channel and PL Coding site. He made a good video covering the difference between MVVM vs. MVI and also explains his hybrid approach. I strongly recommend watching this video if you haven't already.
Code Examples
Please look at the Code Examples (not yet posted) before continuing any further. In that post, I cover a minimal example of MVI, a practical example, and a comparison with MVVM.
Reminder: Please read Code Examples (not yet posted) before continuing.
MVI (UDF) vs. MVVM Summary
MVI (UDF) vs. MVVM Confusion
- The names are very similar so not easy to remember. A more distinct name would have been far easier for people to link the ideas.
- The difference is not really clearly reflected in the name.
Naming
- Both - M - Model (Data / Repository)
- Both - V - View (UI)
- MVI - I - Intent (Action)
- MVVM - VM - ViewModel
Simplified Diagram
MVI (UDF) & MVVM Diagram for Android Compose
- UI Actions - One function to pass requests to the ViewModel
- UI State - One data class that passes up the entire UI State for display to the user
- UI Actions - Individual calls to the ViewModel
- UI State - Individual values that can be requested from the ViewModel
Final Thoughts
Links
My links
GitHub Gists
Posts
- Code Examples
- MVI - Desired State Pattern (work in progress - not yet live)
- MVI - Action Handler (work in progress - not yet live)
Official links
Google:
- Android Jetpack Compose
- Recommendations for Android architecture - Labeled UDF (Unidirectional Data Flow)
Other Links
Philipp Lackner (YouTube / Website) - Recommended Videos
References
- Yes, That’s MVI - Pro Android Dev Post
- MVVM - Microsoft .Net Link

Comments
Post a Comment