Android Development • Interview Preparation
MVC, MVP, MVVM, MVI & Clean Architecture
Learn Android architecture from zero in very easy English. One Medicine Reminder app example, simple Kotlin code, diagrams and ready-to-speak interview answers.
1. First understand: What is Architecture?
Architecture means how we organize our app’s code.
Imagine you are building a Medicine Reminder Android app. The app has three main jobs: show information on the screen, get information from an API or database, and decide what to do when the user clicks something.
Our example app
💊 My Medicines
This is only a visual example, not an active app button.
When the user clicks Load Medicines, the app must fetch and display the medicine list.
Without good architecture, we might write API calls, click handling, data processing and UI updates inside a single Activity. As the app grows, that becomes difficult to maintain.
Architecture helps separate these responsibilities.
2. MVC — Model View Controller
Difficulty: Easy • An important older architecture pattern
MVC has three parts:
| Part | Very easy meaning | Android example |
|---|---|---|
| Model | Handles data and related logic | Medicine data, repository |
| View | Shows information | XML layout |
| Controller | Handles actions and coordinates Model and View | Activity |
How MVC works
The Controller gets the data and updates the View (XML screen).
Simple example in Kotlin
object MedicineModel {
fun getMedicines(): List<String> {
return listOf("Paracetamol", "Vitamin D")
}
}class MedicineActivity : AppCompatActivity() {
// Called when user clicks the button
fun onLoadClicked() {
// Get data from Model
val medicines = MedicineModel.getMedicines()
// Update the View
medicineTextView.text = medicines.joinToString()
}
}In this simplified snippet, medicineTextView represents a TextView already connected to the XML layout.
Understand the flow: User clicks button → Activity handles click → Activity asks Model for medicines → Activity updates XML screen.
Problem with MVC
Imagine an Activity with 2,000 lines of code: API calls, validation, click events and UI updates. The Activity can become too large and hard to test. Developers often call this a Fat Activity or Massive Activity.
MVC stands for Model View Controller. Model handles data, View displays the UI, and Controller handles user actions. In Android, an Activity often acts as the Controller. A common problem is that the Activity can become too large and difficult to test.
Q. Why is MVC less preferred for large Android apps?
Answer: Because too much logic can end up inside Activities or Fragments, making the app difficult to maintain and test.
3. MVP — Model View Presenter
Difficulty: Easy to Medium • Better separation of UI logic
MVP improves how we separate the screen and its logic.
| Part | Responsibility |
|---|---|
| Model | Provides medicine data |
| View | Activity/Fragment displays data |
| Presenter | Handles UI logic and tells View what to show |
How MVP works
User actions go to the Presenter. The Presenter gets data and calls View methods to update the screen.
Step 1 — Create a View interface
An interface is like a contract. It tells us which functions a class must provide.
interface MedicineView {
fun showMedicines(medicines: List<String>)
}Step 2 — Create Presenter
class MedicinePresenter(
private val view: MedicineView
) {
fun loadMedicines() {
val medicines = MedicineModel.getMedicines()
// Tell the View to show the list
view.showMedicines(medicines)
}
}Step 3 — Activity implements View interface
class MedicineActivity :
AppCompatActivity(), MedicineView {
private val presenter = MedicinePresenter(this)
fun onLoadClicked() {
presenter.loadMedicines()
}
override fun showMedicines(medicines: List<String>) {
medicineTextView.text = medicines.joinToString()
}
}Understand in very easy English
The Activity says: “Presenter, the user clicked the button.” Presenter asks Model for medicines. Model returns medicines. Presenter says: “View, show these medicines.”
Big difference from MVC: The Presenter handles UI logic instead of putting all that logic in Activity.
Advantages and disadvantages
Advantages: The Presenter is easier to unit test, and UI logic is better separated from the Activity.
Disadvantages: You may need many interfaces. The Presenter commonly holds a View reference, so you must handle its lifecycle carefully to avoid memory leaks.
MVP stands for Model View Presenter. The View handles UI, the Model handles data, and Presenter handles UI logic. Presenter communicates with View through an interface. It improves separation and testability compared to putting all logic inside Activity.
Q. What is the difference between Controller and Presenter?
Answer: In common Android MVC, the Activity often acts as Controller and may handle both UI and logic. In MVP, Presenter is a separate class that handles UI logic, while Activity mainly displays UI.
4. MVVM — Model View ViewModel
Very important for Android interviewsMVVM is one of the most widely used patterns in modern Android applications.
| Part | Meaning |
|---|---|
| Model | Data and business logic, often accessed through repositories |
| View | XML UI or Jetpack Compose |
| ViewModel | Holds UI data/state and handles screen logic |
Understand MVVM with a diagram
The View sends user actions to ViewModel. ViewModel exposes state that the View observes.
Most important word: Observe
Observe means watching for changes.
When ViewModel gets a new medicine list, the View updates because it observes ViewModel state.
In MVP, Presenter commonly calls view.showMedicines(). In MVVM, ViewModel updates _medicines.value = medicines, and the View observes the new data.
Step 1 — Model / Repository
object MedicineRepository {
fun getMedicines(): List<String> {
return listOf("Paracetamol", "Vitamin D")
}
}A Repository provides data to other parts of the app. In a real app, it might get data from Retrofit or Room.
Step 2 — ViewModel
class MedicineViewModel : ViewModel() {
private val _medicines =
MutableStateFlow<List<String>>(emptyList())
val medicines = _medicines.asStateFlow()
fun loadMedicines() {
val result = MedicineRepository.getMedicines()
_medicines.value = result
}
}| Code | Easy explanation |
|---|---|
ViewModel() | Android class for managing UI data and logic |
MutableStateFlow | Holds data that can change |
emptyList() | Initially no medicines |
_medicines.value = result | Updates the data |
asStateFlow() | Exposes read-only state to the UI |
Step 3 — View observes ViewModel
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.medicines.collect { medicines ->
medicineTextView.text = medicines.joinToString()
}
}
}collect means “listen for new values.” repeatOnLifecycle keeps observation lifecycle-aware.
When the user clicks the button, call:
viewModel.loadMedicines()Now ViewModel updates its StateFlow, and the screen receives the medicine list.
Why is MVVM so useful?
Imagine the user rotates the phone. The Activity may be recreated, but the Android ViewModel normally survives configuration changes such as rotation. It can retain the UI state.
ViewModel does not automatically survive process death. Use SavedStateHandle or persistent storage when needed.
MVVM stands for Model View ViewModel. Model handles data, View displays UI, and ViewModel manages UI state and logic. The View observes data from ViewModel using StateFlow or LiveData. MVVM improves testability, separation and handling of configuration changes.
Common MVVM cross-questions
Q. Does ViewModel directly update TextView?
Answer: No. ViewModel updates data/state, and the View observes and displays it.
Q. What is LiveData vs StateFlow?
Answer: Both can hold observable UI data. LiveData is lifecycle-aware by itself. StateFlow is based on Kotlin Flow and normally uses lifecycle-aware collection in the Android UI.
Q. Can ViewModel call Retrofit directly?
Answer: Technically yes, but in a well-structured app it usually calls a Repository or UseCase.
Q. Should ViewModel store Activity or View references?
Answer: Normally no. Holding those references may cause memory leaks.
5. MVI — Model View Intent
Difficulty: Medium • Focuses on predictable state management
MVI is similar to MVVM but commonly follows a more structured approach to user actions and UI state.
Intent: What the user wants to do, for example, LoadMedicines.
State: What the screen currently looks like: Loading, Success or Error.
MVI Intent is an architecture concept. It is not the same as the Android Intent class used to start Activities.
How MVI works
This is called unidirectional data flow: the data moves in a predictable direction.
Understand UI State
Fetching medicines. Show progress.
Medicines loaded. Show list.
Something failed. Show error or retry.
MVI commonly puts the information needed for the whole screen into one UI state object.
Step 1 — Create Intent
sealed interface MedicineIntent {
data object LoadMedicines : MedicineIntent
}A sealed interface defines a known set of possible types. Here there is one action: loading medicines.
Step 2 — Create UI State
data class MedicineUiState(
val isLoading: Boolean = false,
val medicines: List<String> = emptyList(),
val error: String? = null
)isLoading = true means show loading; medicines data means show the list; and a non-null error means show a problem message.
Step 3 — ViewModel handles Intent
class MedicineMviViewModel : ViewModel() {
private val _state =
MutableStateFlow(MedicineUiState())
val state = _state.asStateFlow()
fun onIntent(intent: MedicineIntent) {
when (intent) {
MedicineIntent.LoadMedicines -> {
_state.value =
_state.value.copy(isLoading = true)
val result =
MedicineRepository.getMedicines()
_state.value = MedicineUiState(
medicines = result
)
}
}
}
}This local-data example is intentionally simple. For a real API request, use coroutines, error handling and appropriate loading-state updates.
Step 4 — View sends Intent
viewModel.onIntent(MedicineIntent.LoadMedicines)The View observes the ViewModel state and displays medicines, a loading indicator or an error.
Most important concept: Unidirectional Data Flow
Unidirectional means one direction. User Action → Intent → Logic → New State → UI. We do not randomly change UI state from multiple places.
MVI often uses a Reducer: a function that takes the current state and an event or result and returns the next state. Simpler MVI-style implementations update state directly inside ViewModel.
MVI stands for Model View Intent. The View sends user actions as Intents. The logic processes those actions and produces a new UI state. The View observes that state. MVI follows unidirectional data flow, making UI changes more predictable.
Q. What is the main difference between MVVM and MVI?
Answer: MVVM separates View and ViewModel with observable state. MVI adds a more structured action-to-state flow, commonly using explicit Intents and one screen state. MVI can be implemented using Android ViewModel.
6. Clean Architecture
Difficulty: Medium • Very useful for large applications
MVC, MVP, MVVM and MVI mainly explain how UI and screen logic communicate.
Clean Architecture explains how we organize the wider application so different parts stay independent. You can combine MVVM + Clean Architecture.
The three layers
Arrows above show a typical request moving through the app. The dependency rule differs: Domain should not depend on Data or Android UI classes. Data can implement interfaces defined in Domain.
Layer 1 — Presentation: What the user sees
User clicks Load Medicines. View sends the action to ViewModel. ViewModel requests medicine data and updates UI state. Presentation manages how the screen behaves and what it displays.
Layer 2 — Domain: What the app should do
Domain holds business rules. For example, a medicine scheduled for 9 AM should be considered due at 9 AM. This rule should not live inside TextView or Activity.
A UseCase represents one meaningful action, like GetMedicinesUseCase or ScheduleMedicineReminderUseCase.
class GetMedicinesUseCase(
private val repository: MedicineRepository
) {
suspend operator fun invoke(): List<Medicine> {
return repository.getMedicines()
}
}suspend means the function can be called from a coroutine and may perform suspending work.
Layer 3 — Data: Where information comes from
The Data layer manages Retrofit APIs, Room database and other data sources. First, the Domain layer defines a Repository interface:
interface MedicineRepository {
suspend fun getMedicines(): List<Medicine>
}Then the Data layer provides a concrete implementation:
class MedicineRepositoryImpl(
private val api: MedicineApi
) : MedicineRepository {
override suspend fun getMedicines(): List<Medicine> {
return api.getMedicines()
}
}Medicine represents a Domain data class and MedicineApi represents a Retrofit API interface. In real apps, map network response models to Domain models as needed. The snippets in different architecture sections are separate teaching examples.
Complete Clean Architecture flow
The response returns through the layers. ViewModel updates the UI state and the screen displays the result.
Example project folder structure
com.example.medicineapp
│
├── presentation/
│ ├── MedicineScreen.kt
│ └── MedicineViewModel.kt
│
├── domain/
│ ├── model/
│ │ └── Medicine.kt
│ ├── repository/
│ │ └── MedicineRepository.kt
│ └── usecase/
│ └── GetMedicinesUseCase.kt
│
└── data/
├── remote/
│ └── MedicineApi.kt
├── local/
│ └── MedicineDao.kt
└── repository/
└── MedicineRepositoryImpl.ktIf tomorrow your company changes Retrofit to another networking library, most of the required changes can stay in the Data layer. Ideally, your Domain rules and UI need few or no changes.
Is a UseCase mandatory?
No. For a simple app, ViewModel → Repository may be enough. UseCases are especially useful when business logic is complex or reused.
Clean Architecture divides the application into independent layers, commonly Presentation, Domain and Data. Presentation handles UI, Domain handles business rules and UseCases, and Data handles APIs and databases. It makes code easier to test, maintain and change.
7. MVC vs MVP vs MVVM vs MVI vs Clean Architecture
Read this table two or three times. It is one of the easiest ways to remember the difference.
| Architecture | Main idea | Main characteristic |
|---|---|---|
| MVC | Controller coordinates View and Model | Activity often handles too much |
| MVP | Presenter handles UI logic | Presenter tells View what to show |
| MVVM | View observes ViewModel | StateFlow / LiveData |
| MVI | Actions produce new UI state | One-way state flow |
| Clean Architecture | Organizes the whole app into layers | Separation and independence |
8. Easy Memory Trick
Controller controls the flow.
Presenter tells View what to show.
View observes ViewModel state.
Intent comes in, new State comes out.
Separate UI, business rules and data.
9. Top 10 Android Interview Questions
These are short, ready-to-speak answers for Android Developer interviews.
Q. Which architecture is best for Android?
Answer: For many modern Android applications, MVVM with repositories is a good choice. Add Clean Architecture layers when the app becomes more complex. MVI-style state management is useful for complex screens.
Q. What is the main difference between MVP and MVVM?
Answer: MVP Presenter commonly calls View methods through an interface. In MVVM, ViewModel exposes observable state, and the View observes that state.
Q. Can we use MVVM with Clean Architecture?
Answer: Yes. MVVM can structure the Presentation layer, while Clean Architecture organizes Presentation, Domain and Data layers.
Q. Why use Repository in Android?
Answer: Repository separates data access from UI logic. It can work with Retrofit, Room or other data sources.
Q. What is the role of UseCase?
Answer: A UseCase represents one business action, such as getting medicines or scheduling reminders. It is useful for reusable or complex logic.
Q. Can MVI and MVVM work together?
Answer: Yes. A ViewModel can receive Intents and expose one UiState, so MVI-style state handling can be used within MVVM.
Q. Why is MVVM easier to test than a large MVC Activity?
Answer: Because ViewModel logic can be tested separately without creating a full Android screen.
Q. What happens when an API fails in MVVM?
Answer: The Repository returns or throws an error, the ViewModel handles it, and the ViewModel updates UI state so the View can show an error or retry option.
Q. What is Dependency Injection in Clean Architecture?
Answer: It means giving a class the dependencies it needs instead of creating everything inside it. For example, Hilt can provide a Repository to a UseCase or ViewModel.
Q. Is Clean Architecture always required?
Answer: No. For small applications, simple MVVM with a Repository can be enough. We should choose complexity based on project needs.