<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amitabh Sharma on Medium]]></title>
        <description><![CDATA[Stories by Amitabh Sharma on Medium]]></description>
        <link>https://medium.com/@amit4app?source=rss-022893e95e79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FOOam0zq1EY-M6Bb</url>
            <title>Stories by Amitabh Sharma on Medium</title>
            <link>https://medium.com/@amit4app?source=rss-022893e95e79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 11:40:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amit4app/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Built a Video Upload Feature That Never Fails — Thanks to WorkManager]]></title>
            <link>https://medium.com/@amit4app/how-i-built-a-video-upload-feature-that-never-fails-thanks-to-workmanager-67416b8e721a?source=rss-022893e95e79------2</link>
            <guid isPermaLink="false">https://medium.com/p/67416b8e721a</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[workmanager]]></category>
            <dc:creator><![CDATA[Amitabh Sharma]]></dc:creator>
            <pubDate>Sat, 09 Aug 2025 05:03:07 GMT</pubDate>
            <atom:updated>2025-08-10T10:40:21.044Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4XRqFEt_yvV2D02eEykug.png" /></figure><h3>How I Built a Video Upload Feature That Never Fails — Thanks to WorkManager</h3><h3>Introduction:</h3><p>If you’ve ever built a file upload feature in Android, you know the pain:</p><ul><li>App gets killed? Upload gone.</li><li>Network drops? Upload gone.</li><li>User restarts phone? Upload gone.</li></ul><p>I recently worked on a demo where I <strong>uploaded a large video file using WorkManager</strong> — and the upload kept going even after:<br> ✔ Killing the app<br> ✔ Network interruptions<br> ✔ Device reboots</p><p>In this post, I’ll show you <strong>how WorkManager makes this possible</strong>, and share the <strong>full code</strong> so you can try it yourself.</p><h3>Why WorkManager?</h3><p>WorkManager is part of Android Jetpack and is <strong>the go-to API for guaranteed background work</strong>.<br> It’s perfect for:</p><ul><li>Uploads &amp; downloads</li><li>Data sync</li><li>Sending logs</li><li>Any task that must run <strong>even if the app is not in the foreground</strong></li></ul><p><strong>Key features that helped in my case:</strong></p><ul><li><strong>Guaranteed execution</strong> (reschedules after failures)</li><li><strong>Respects battery &amp; OS constraints</strong></li><li><strong>Handles network changes</strong></li><li><strong>Persists across app restarts and reboots</strong></li></ul><h3>The Demo</h3><p>In my case, I wanted to:</p><ol><li>Let the user pick a video file using the <strong>Storage Access Framework</strong></li><li>Upload it in the background using <strong>WorkManager + Foreground Service</strong></li><li>Show upload progress in the UI</li><li>Resume upload even after app kill or reboot</li></ol><h3>What Happens When…</h3><ul><li><strong>App is killed</strong> → Upload continues in background</li><li><strong>Network drops</strong> → WorkManager retries when it’s back</li><li><strong>Phone restarts</strong> → Upload resumes automatically</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*RSMJw-dkN71796p2tRIGmw.gif" /></figure><p>Here’s how I built it 👇</p><h3>1. The Worker — Where the background magic happens</h3><p>This is the heart of WorkManager.<br> A Worker (or CoroutineWorker in this case) defines <strong>what will run in the background</strong>. Here we:</p><ul><li>Take the video’s URI from the input data</li><li>Simulate the upload process with a loop (you can replace it with a real API call)</li><li>Continuously update the progress so the UI can show it in real time</li></ul><pre>class FileUploadWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(ctx, params) {<br><br>    companion object {<br>        const val KEY_FILE_URI = &quot;file_uri&quot;<br>        const val KEY_UPLOAD_ID = &quot;upload_id&quot;<br>        const val PROGRESS = &quot;progress&quot;<br>    }<br><br>    override suspend fun doWork(): Result {<br>        val uriString = inputData.getString(KEY_FILE_URI) ?: return Result.failure()<br>        val fileUri = Uri.parse(uriString)<br><br>        // Simulate upload<br>        for (i in 1..100) {<br>            delay(200) // simulate chunk upload<br>            setProgress(workDataOf(PROGRESS to i))<br>        }<br><br>        return Result.success()<br>    }<br>}</pre><h3>2. The UI (Jetpack Compose) — Where the user sees and controls uploads</h3><p>This is the <strong>front-facing layer</strong>. It:</p><ul><li>Lets the user pick a video file using the system picker</li><li>Displays the selected file, upload progress, and state</li><li>Enqueues the Worker to start the upload</li><li>Observes progress changes from WorkManager and updates the UI</li></ul><pre>@Composable<br>fun UploadScreen() {<br>    val ctx = LocalContext.current<br>    var pickedUri by remember { mutableStateOf&lt;Uri?&gt;(null) }<br>    var progress by remember { mutableStateOf(0) }<br>    var state by remember { mutableStateOf(WorkInfo.State.ENQUEUED) }<br><br>    val pickVideo = rememberLauncherForActivityResult(<br>        ActivityResultContracts.OpenDocument()<br>    ) { uri -&gt;<br>        uri?.let {<br>            ctx.contentResolver.takePersistableUriPermission(it, Intent.FLAG_GRANT_READ_URI_PERMISSION)<br>            pickedUri = it<br>        }<br>    }<br><br>    Column(Modifier.padding(16.dp)) {<br>        Button(onClick = { pickVideo.launch(arrayOf(&quot;video/*&quot;)) }) {<br>            Text(&quot;Pick Video&quot;)<br>        }<br><br>        if (pickedUri != null) {<br>            Text(&quot;Selected: $pickedUri&quot;)<br>            LinearProgressIndicator(progress / 100f)<br>            Text(&quot;$progress% • $state&quot;)<br><br>            Button(onClick = {<br>                val req = OneTimeWorkRequestBuilder&lt;FileUploadWorker&gt;()<br>                    .setInputData(<br>                        workDataOf(<br>                            FileUploadWorker.KEY_FILE_URI to pickedUri.toString(),<br>                            FileUploadWorker.KEY_UPLOAD_ID to pickedUri.toString()<br>                        )<br>                    )<br>                    .build()<br><br>                WorkManager.getInstance(ctx).enqueue(req)<br><br>                WorkManager.getInstance(ctx).getWorkInfoByIdLiveData(req.id)<br>                    .observeForever { info -&gt;<br>                        progress = info?.progress?.getInt(FileUploadWorker.PROGRESS, 0) ?: 0<br>                        state = info?.state ?: WorkInfo.State.ENQUEUED<br>                    }<br>            }) {<br>                Text(&quot;Start Upload&quot;)<br>            }<br>        }<br>    }<br>}</pre><h3>3. The Manifest — Giving WorkManager permission to run in the foreground</h3><p>When WorkManager runs long tasks like uploads, it can use a <strong>Foreground Service</strong> so the OS keeps it alive.<br> Here we override WorkManager’s internal foreground service to specify dataSync as the type — this is required from Android 14 onwards for stricter foreground service permissions.</p><pre>&lt;service<br>    android:name=&quot;androidx.work.impl.foreground.SystemForegroundService&quot;<br>    android:exported=&quot;false&quot;<br>    android:foregroundServiceType=&quot;dataSync&quot; /&gt;</pre><h3>Conclusion</h3><p>WorkManager might look simple at first glance, but it’s built for reliability.<br> Unlike plain threads or coroutines tied to your Activity, WorkManager:</p><ul><li>Survives app kills, device reboots, and network drops</li><li>Runs even under strict background restrictions in modern Android</li><li>Handles retry, constraints, and chaining out of the box</li></ul><p>In this demo, we showed how to:</p><ul><li>Pick a large video file locally</li><li>Upload it with real-time progress updates in Jetpack Compose</li><li>Ensure the task continues even if you close the app</li></ul><p>This is why WorkManager is the go-to choice for guaranteed background tasks — whether it’s syncing data, uploading media, or doing heavy local processing.</p><p>You can explore the full code for this demo on <a href="https://github.com/amit4app/Work-Manager-Video-Upload">GitHub</a>.</p><p>Have you used WorkManager in your projects?<br> Share your thoughts, use cases, or any challenges you’ve faced in the comments — and feel free to share this post with other Android devs who might find it useful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67416b8e721a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVC, MVP, MVVM, Clean, and MVI Explained]]></title>
            <link>https://medium.com/@amit4app/mvc-mvp-mvvm-clean-and-mvi-explained-41d35eb2b085?source=rss-022893e95e79------2</link>
            <guid isPermaLink="false">https://medium.com/p/41d35eb2b085</guid>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mvi]]></category>
            <dc:creator><![CDATA[Amitabh Sharma]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 05:21:00 GMT</pubDate>
            <atom:updated>2025-08-09T21:08:39.587Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cvatOKWULwhurvMJKrHJMA.png" /></figure><h3>Introduction: Why Architecture Matters</h3><p>If you’ve been building Android apps for a while, you’ve probably realized that as your app grows, things start to get messy — activities stuffed with business logic, network calls sprinkled everywhere, and UI updates tangled with data handling.</p><p>The solution? A solid architecture.</p><p>A good architecture:</p><ul><li>Keeps your code clean, maintainable, and testable</li><li>Makes scaling easy as your app grows</li><li>Improves team collaboration</li></ul><p>In this blog, we’ll take a journey through the evolution of Android architecture, from classic MVC to modern MVI, including MVP, MVVM, and Clean Architecture — with diagrams and Kotlin examples.</p><h3>The Evolution of Android Architecture:</h3><p>Why so many patterns? Because apps evolved.</p><ul><li>Early Android (MVC): Activities controlled everything.</li><li>MVP: Introduced a Presenter to reduce Activity bloat.</li><li>MVVM: Google’s preferred pattern for lifecycle awareness and reactive UIs.</li><li>Clean Architecture: Perfect for enterprise-scale apps.</li><li>MVI: Great for state-driven UI like Jetpack Compose.</li></ul><h3>1. MVC (Model-View-Controller) — The Classic Pattern</h3><h3>What is MVC?</h3><p>MVC is one of the oldest design patterns that divides an application into three interconnected components:</p><ul><li>Model: Represents data and business logic. Handles data storage, API calls, and database operations.</li><li>View: Represents the user interface. Displays data to the user and sends user actions to the Controller.</li><li>Controller: Acts as a mediator between View and Model. It processes user input, updates the Model, and refreshes the View.</li></ul><h3>Diagram:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CCa1Cq46lt1gkfd5ctM1sw.png" /></figure><h3>MVC Folder Structure:</h3><pre>app/<br> ├── model/<br> │    └── User.kt<br> ├── view/<br> │    └── activity_main.xml<br> ├── controller/<br> │    └── MainActivity.kt  // Acts as both Controller &amp; View in Android</pre><h3>Data Flow:</h3><ul><li>Controller fetches Model data</li><li>Updates View when data changes</li></ul><h3>Kotlin Code Example:</h3><pre><br>// --- Model ---<br>data class User(val name: String, val age: Int)<br><br>// --- Controller ---<br>// Depends on the concrete View (MainActivity) — NOT an interface<br>class UserController(private val activity: MainActivity) {<br><br>    fun loadUser() {<br>        val user = User(name = &quot;John&quot;, age = 25)<br><br>        // Update the concrete View directly.<br>        activity.renderUser(user)<br>    }<br>}<br><br>// --- View (Activity) ---<br>class MainActivity : AppCompatActivity() {<br><br>    private lateinit var controller: UserController<br>    private lateinit var textView: TextView <br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_main)<br><br>        textView = findViewById(R.id.textView)<br>        controller = UserController(this)<br><br>        controller.loadUser()<br>    }<br><br>    // Called by Controller — MVC style (no interface).<br>    fun renderUser(user: User) {<br>        textView.text = &quot;${user.name}, ${user.age}&quot;<br>    }<br>}</pre><h3>Pros:</h3><ul><li>Simple and easy to start</li><li>Good for very small apps</li></ul><h3>Cons:</h3><ul><li>Activity often becomes God class (does everything)</li><li>Hard to maintain and test for big applications.</li><li>Tight coupling between UI and logic</li></ul><h3>2. MVP (Model-View-Presenter) — The First Big Step</h3><h3>What is MVP?</h3><p>MVP is an improvement over MVC, introduced to separate UI logic from business logic more effectively.</p><ul><li>Model: Data layer (APIs, DB).</li><li>View: UI layer, represented by Activity or Fragment (implements a View Interface).</li><li>Presenter: Contains presentation logic, communicates with Model and updates View.</li></ul><h3>Diagram:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v_1v8CkWk97kxtP4dDPXXA.png" /></figure><h3>MVP Folder Structure:</h3><pre>app/<br> ├── model/<br> │    └── User.kt<br> ├── presenter/<br> │    └── UserPresenter.kt<br> ├── view/<br> │    ├── UserView.kt      // Interface<br> │    └── MainActivity.kt  // Implements UserView</pre><h3>Kotlin Code Example:</h3><pre>// Model: Represents data<br>data class User(val name: String, val age: Int)<br><br>// View Interface<br>interface UserView {<br>    fun showUser(user: User)<br>}<br><br>// Presenter<br>class UserPresenter(private val view: UserView) {<br>    fun loadUser() {<br>        val user = User(&quot;John Doe&quot;, 30)<br>        view.showUser(user)<br>    }<br>}<br><br>// Activity<br>class MainActivity : AppCompatActivity(), UserView {<br>    private lateinit var presenter: UserPresenter<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_main)<br><br>        presenter = UserPresenter(this)<br>        presenter.loadUser()<br>    }<br><br>    override fun showUser(user: User) {<br>        findViewById&lt;TextView&gt;(R.id.textView).text = &quot;${user.name}, ${user.age}&quot;<br>    }<br>}</pre><h3>Pros:</h3><ul><li>Easier to test Presenter since it’s independent of Android components.</li><li>View is passive and only displays data provided by Presenter.</li></ul><h3>Cons:</h3><ul><li>Presenter can still grow very large in complex apps.</li><li>Requires manual binding between View and Presenter.</li></ul><h3>3. MVVM (Model-View-ViewModel) — The Modern Standard</h3><h3>What is MVVM?</h3><p>MVVM is a pattern recommended by Google for Android. It uses data binding or reactive streams to reduce boilerplate code.</p><ul><li>Model: Responsible for data and business logic.</li><li>View: UI layer (Activity, Fragment) observes ViewModel.</li><li>ViewModel: Stores UI-related data, survives configuration changes, and exposes data via LiveData or StateFlow.</li></ul><h3>Diagram:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3egU39m6P95dVkbqvD1D6g.png" /></figure><h3>MVVM Folder Structure:</h3><pre>app/<br> ├── model/<br> │    └── User.kt<br> ├── view/<br> │    ├── activity_main.xml<br> │    └── MainActivity.kt<br> ├── viewmodel/<br> │    └── UserViewModel.kt</pre><h3>Kotlin Code Example:</h3><pre>// ======================<br>// Model<br>// ======================<br>data class User(val name: String, val age: Int)<br><br>// ======================<br>// ViewModel<br>// Holds the UI data and business logic<br>// ======================<br>class UserViewModel : ViewModel() {<br><br>    // LiveData to observe changes in UI<br>    private val _user = MutableLiveData&lt;User&gt;()<br>    val user: LiveData&lt;User&gt; = _user<br><br>    // Simulate fetching user data (normally from Repository)<br>    fun fetchUser() {<br>        _user.value = User(&quot;John Doe&quot;, 30)<br>    }<br>}<br><br>// ======================<br>// View (Activity)<br>// Observes the ViewModel and updates the UI<br>// ======================<br>class MainActivity : AppCompatActivity() {<br><br>    private lateinit var viewModel: UserViewModel<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_main)<br><br>        // Initialize ViewModel<br>        viewModel = ViewModelProvider(this).get(UserViewModel::class.java)<br><br>        // Observe LiveData for changes<br>        viewModel.user.observe(this) { user -&gt;<br>            // Update UI when data changes<br>            findViewById&lt;TextView&gt;(R.id.textView).text = &quot;${user.name}, ${user.age}&quot;<br>        }<br><br>        // Fetch user data when Activity starts<br>        viewModel.fetchUser()<br>    }<br>}</pre><h3>Pros:</h3><ul><li>No direct reference between View and ViewModel (reduces memory leaks).</li><li>Great for reactive UI with LiveData or Flow.</li><li>Highly testable.</li></ul><h3>Cons:</h3><ul><li>Slightly more complex than MVP for beginners.</li></ul><h3>4. Clean Architecture — For Large Apps</h3><h3>What is Clean Architecture?</h3><p>Clean Architecture is a layered architecture proposed by Robert C. Martin (Uncle Bob). It organizes code into layers with strict dependency rules:</p><ul><li>Presentation Layer: UI and ViewModel.</li><li>Domain Layer: Business rules, use cases, entities (pure Kotlin/Java, independent of Android).</li><li>Data Layer: Repositories, APIs, databases.</li></ul><h3>Principles:</h3><ul><li>Dependency direction is always inward (UI → Domain → Data).</li><li>Each layer is independent and testable.</li></ul><h3>Best Practice:</h3><ul><li>Use Hilt for DI</li><li>Coroutines + Flow for async tasks</li><li>Multi-module for faster builds</li></ul><h3>Diagram:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*5ALCFqSLb5F9KM1qoaiAJg.png" /></figure><h3>Clean Architecture Folder Structure:</h3><pre>app/<br> ├── presentation/<br> │    ├── view/<br> │    │    └── MainActivity.kt<br> │    └── viewmodel/<br> │         └── UserViewModel.kt<br> ├── domain/<br> │    ├── model/<br> │    │    └── User.kt<br> │    ├── repository/<br> │    │    └── UserRepository.kt<br> │    └── usecase/<br> │         └── GetUserUseCase.kt<br> ├── data/<br> │    ├── repository/<br> │    │    └── UserRepositoryImpl.kt<br> │    ├── remote/<br> │    │    └── ApiService.kt<br> │    └── local/<br> │         └── UserDao.ktKotlin Code Example:</pre><pre>// =============================<br>// Domain Layer (Independent of frameworks)<br>// =============================<br><br>// Entity (Business object)<br>data class User(val name: String, val age: Int)<br><br>// Repository Interface (Abstraction)<br>interface UserRepository {<br>    fun getUser(): User<br>}<br><br>// Use Case (Business logic)<br>class GetUserUseCase(private val repository: UserRepository) {<br>    operator fun invoke(): User {<br>        // Here you can add additional business rules if needed<br>        return repository.getUser()<br>    }<br>}<br><br>// =============================<br>// Data Layer (Implements Repository)<br>// =============================<br><br>// Repository Implementation (Uses data sources)<br>class UserRepositoryImpl : UserRepository {<br>    override fun getUser(): User {<br>        // In real-world, fetch from API or Database<br>        return User(&quot;John Doe&quot;, 30)<br>    }<br>}<br><br>// =============================<br>// Presentation Layer (UI + ViewModel)<br>// =============================<br><br>class UserViewModel(private val getUserUseCase: GetUserUseCase) : ViewModel() {<br><br>    // LiveData to expose data to UI<br>    private val _user = MutableLiveData&lt;User&gt;()<br>    val user: LiveData&lt;User&gt; get() = _user<br><br>    fun fetchUser() {<br>        // Call the UseCase to get user data<br>        _user.value = getUserUseCase()<br>    }<br>}<br><br>// =============================<br>// View (Activity)<br>// =============================<br><br>class MainActivity : AppCompatActivity() {<br><br>    private lateinit var viewModel: UserViewModel<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_main)<br><br>        // Manual DI for simplicity (Hilt/Dagger recommended in real projects)<br>        val repository = UserRepositoryImpl()<br>        val useCase = GetUserUseCase(repository)<br>        viewModel = UserViewModel(useCase)<br><br>        // Observe LiveData to update UI<br>        viewModel.user.observe(this) { user -&gt;<br>            findViewById&lt;TextView&gt;(R.id.textView).text = &quot;${user.name}, ${user.age}&quot;<br>        }<br><br>        // Fetch user when screen loads<br>        viewModel.fetchUser()<br>    }<br>}</pre><h3>Pros:</h3><ul><li>Scalable and maintainable for large applications.</li><li>Allows easy replacement of frameworks or data sources.</li></ul><h3>Cons:</h3><ul><li>Initial setup requires more effort and boilerplate.</li></ul><h3>5. MVI (Model-View-Intent) — The Reactive Future</h3><h3>What is MVI?</h3><p>MVI is a reactive, unidirectional architecture inspired by Redux. It focuses on managing state in a predictable way.</p><ul><li>Model: Represents the entire UI state as an immutable object.</li><li>View: Displays the state and sends user intents.</li><li>Intent: Represents user actions, which trigger state changes.</li></ul><h3>Diagram:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzLyn4cmPmqIq8IRy-l6ew.png" /></figure><h3>MVI Folder Structure:</h3><pre>app/<br> ├─ intent/       → UserIntent.kt (UI events)<br> ├─ state/        → UserState.kt (immutable UI state)<br> ├─ viewmodel/    → UserViewModel.kt (process intents → state)<br> ├─ repository/   → UserRepository.kt (fetch data from Local/Remote)<br> └─ ui/           → MainScreen.kt (render + send intents)</pre><h3>Kotlin Code Example:</h3><pre>// Intent<br>sealed class UserIntent { object LoadUser : UserIntent() }<br><br>// State<br>data class UserState(val isLoading: Boolean = false, val name: String = &quot;&quot;, val error: String? = null)<br><br>// ViewModel<br>class UserViewModel(private val repo: UserRepository) : ViewModel() {<br>    val state = MutableStateFlow(UserState())<br><br>    fun process(intent: UserIntent) {<br>        when (intent) {<br>            UserIntent.LoadUser -&gt; viewModelScope.launch {<br>                state.value = state.value.copy(isLoading = true)<br>                try {<br>                    val user = repo.getUser()<br>                    state.value = UserState(name = user.name)<br>                } catch (e: Exception) {<br>                    state.value = UserState(error = e.message)<br>                }<br>            }<br>        }<br>    }<br>}<br><br>// View (Compose)<br>@Composable<br>fun MainScreen(vm: UserViewModel) {<br>    val uiState by vm.state.collectAsState()<br>    Button(onClick = { vm.process(UserIntent.LoadUser) }) { Text(&quot;Load&quot;) }<br>    if (uiState.isLoading) CircularProgressIndicator()<br>    if (uiState.error != null) Text(&quot;Error: ${uiState.error}&quot;)<br>    if (uiState.name.isNotEmpty()) Text(&quot;Hello, ${uiState.name}&quot;)<br>}</pre><h3>Pros:</h3><ul><li>Single source of truth for UI state.</li><li>Easy debugging (predictable state changes).</li><li>Ideal for Jetpack Compose or declarative UI.</li></ul><h3>Cons:</h3><ul><li>Can be verbose and complex for simple apps.</li></ul><h3>Comparison Table:</h3><pre>Pattern           Complexity    Testability    Data Flow                               Best For<br>------------------------------------------------------------------------------------------------<br>MVC               Low           Low            Bi-directional (Controller updates)     Small apps<br>MVP               Medium        Medium         Bi-directional (Presenter mediates)     Medium apps<br>MVVM              Medium        High           One-way reactive (View observes VM)     Most apps<br>Clean             High          Very High      Layered one-way (UI → Domain → Data)    Large teams<br>MVI               High          High           Unidirectional (Intent → State → View)  Compose UIs</pre><h3>Conclusion: Which Architecture Should You Choose?</h3><p>Android architecture patterns have evolved for a reason — to make your code maintainable, scalable, and testable. There’s no one-size-fits-all solution; the right pattern depends on your app’s complexity, team size, and long-term goals.</p><ul><li>MVC — Use only for tiny apps or quick prototypes.</li><li>MVP — Works well for small to medium apps where you want some structure but don’t need advanced features.</li><li>MVVM — The modern standard for most Android apps, especially when using Jetpack components or Compose.</li><li>Clean Architecture — Best for enterprise apps, large teams, and projects requiring scalability and testability.</li><li>MVI — Ideal for reactive UIs and Jetpack Compose, providing a single source of truth for state.</li></ul><p>My Recommendation:</p><ul><li>Start with MVVM if you’re building modern apps.</li><li>Move to Clean Architecture for large, complex projects.</li><li>Consider MVI if you’re developing with Jetpack Compose or need unidirectional data flow.</li></ul><p>Your Turn: Which architecture pattern do you use in your apps? Drop a comment below and let’s discuss!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41d35eb2b085" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>