<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Aalaa Fahiem </title>
    <description>The latest articles on Forem by Aalaa Fahiem  (@itsaalaa7).</description>
    <link>https://forem.com/itsaalaa7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3859289%2Fae7b77d0-955c-4c2f-b8d1-43ddb3012a83.png</url>
      <title>Forem: Aalaa Fahiem </title>
      <link>https://forem.com/itsaalaa7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/itsaalaa7"/>
    <language>en</language>
    <item>
      <title>My MainActivity Was 700 Lines Long. That's When I Finally Learned MVVM.</title>
      <dc:creator>Aalaa Fahiem </dc:creator>
      <pubDate>Sun, 05 Apr 2026 15:00:59 +0000</pubDate>
      <link>https://forem.com/itsaalaa7/my-mainactivity-was-700-lines-long-thats-when-i-finally-learned-mvvm-3h7n</link>
      <guid>https://forem.com/itsaalaa7/my-mainactivity-was-700-lines-long-thats-when-i-finally-learned-mvvm-3h7n</guid>
      <description>&lt;p&gt;I'm not even exaggerating with that number. 700 lines. One file. One class. Every single thing my app did — API calls, click listeners, UI updates, data formatting — all crammed into &lt;code&gt;MainActivity.kt&lt;/code&gt; like a suitcase someone sat on to close.&lt;/p&gt;

&lt;p&gt;It worked. Until it didn't.&lt;/p&gt;

&lt;p&gt;The day it fell apart was when I tried to add a simple line of Code. I ended up breaking the list, the error message, and somehow the back button. I spent four hours fixing something that should've taken ten minutes.&lt;/p&gt;

&lt;p&gt;That's when I finally stopped avoiding the word I'd been scared of since I started: &lt;strong&gt;architecture&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I Ignored It For So Long
&lt;/h2&gt;

&lt;p&gt;Honestly? The word itself put me off.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Architecture.&lt;/em&gt; It sounds like something senior engineers debate in long meetings. Not something a beginner building their first to-do app needs to worry about.&lt;/p&gt;

&lt;p&gt;So I kept ignoring it. Kept piling more code into my Activity. Kept telling myself I'd "refactor later."&lt;/p&gt;

&lt;p&gt;Later never came. The code just got worse.&lt;/p&gt;

&lt;p&gt;If you're in that same place right now — I get it. But let me tell you what nobody told me: MVVM isn't complicated. It's actually just a way of answering one question —&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Who is responsible for what?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's it. Seriously.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Analogy That Made It Click For Me
&lt;/h2&gt;

&lt;p&gt;Forget code for a second. Think about a restaurant.&lt;/p&gt;

&lt;p&gt;When you go out to eat, there are three people involved in getting food to your table:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🍽️ &lt;strong&gt;The waiter&lt;/strong&gt; takes your order and brings your food. They don't cook anything. They don't decide what's on the menu. They just deal with &lt;em&gt;you&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;👨‍🍳 &lt;strong&gt;The chef&lt;/strong&gt; does all the actual work. Takes the order from the waiter, figures out how to prepare it, sends it back out. Never comes to your table.&lt;/li&gt;
&lt;li&gt;📦 &lt;strong&gt;The stockroom&lt;/strong&gt; has all the ingredients. The chef goes there to get what they need. You never see it. The waiter definitely doesn't go back there.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Three people. Three jobs. Nobody steps on anyone else's toes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MVVM is exactly this:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your &lt;strong&gt;View&lt;/strong&gt; (Activity, Fragment, Composable) = the waiter. Shows things to the user. Reacts to what the user does. That's all.&lt;/li&gt;
&lt;li&gt;Your &lt;strong&gt;ViewModel&lt;/strong&gt; = the chef. Holds the logic. Decides what data to use and when. Never touches the UI directly.&lt;/li&gt;
&lt;li&gt;Your &lt;strong&gt;Model&lt;/strong&gt; (Repository, database, API) = the stockroom. Just holds and provides data. Doesn't care who's asking or why.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When I understood this, everything else fell into place.&lt;/p&gt;




&lt;h2&gt;
  
  
  What My Code Looked Like Before (Please Don't Judge Me)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MainActivity&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AppCompatActivity&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bundle&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;setContentView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;activity_main&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;// calling the API straight from the Activity 💀&lt;/span&gt;
        &lt;span class="nc"&gt;CoroutineScope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Dispatchers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IO&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;launch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;users&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RetrofitClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="nf"&gt;withContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Dispatchers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submitList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This looks innocent. It's not.&lt;/p&gt;

&lt;p&gt;Rotate the phone → Activity gets destroyed → coroutine gets cancelled&lt;br&gt;
 → the API gets called again from scratch. Every. Single. Rotation.&lt;/p&gt;

&lt;p&gt;Also, try writing a test for this. You can't. The networking is baked directly into the UI layer. There's no way to test the logic without spinning up the whole Activity.&lt;/p&gt;

&lt;p&gt;I didn't even know this was a problem until it bit me.&lt;/p&gt;


&lt;h2&gt;
  
  
  What It Looks Like After
&lt;/h2&gt;

&lt;p&gt;Here's the same feature split across three layers the right way:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Model — just fetches data, nothing else&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserRepository&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;api&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ApiService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The ViewModel — holds the logic and the state&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserViewModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UserRepository&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ViewModel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;_users&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MutableStateFlow&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;(&lt;/span&gt;&lt;span class="nf"&gt;emptyList&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;StateFlow&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_users&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;loadUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;loadUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;viewModelScope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;launch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;_users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The View — just watches and reacts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MainActivity&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AppCompatActivity&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UserViewModel&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="nf"&gt;viewModels&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bundle&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;setContentView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;activity_main&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;lifecycleScope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;launch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;
                &lt;span class="n"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submitList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three files. Each one does one thing. The Activity has no idea how users are fetched. The ViewModel has no idea how they're displayed. And if I rotate the phone? The ViewModel is still alive — data doesn't reload, nothing breaks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwjbg1btw70zuurbx8oay.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwjbg1btw70zuurbx8oay.jpeg" alt=" " width="800" height="745"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The One Thing I Wish Someone Had Told Me
&lt;/h2&gt;

&lt;p&gt;The ViewModel isn't just an organizational trick. It has an actual superpower that nothing else gives you:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It survives configuration changes.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you rotate your phone, Android destroys and recreates your Activity. This is just how Android works — it's not a bug. But if your data lives inside the Activity, it dies with it.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;ViewModel&lt;/code&gt; doesn't. It stays alive across rotations, theme changes, keyboard toggles — anything that would normally kill your Activity. When the Activity comes back, it reconnects to the &lt;em&gt;same&lt;/em&gt; ViewModel that was already there, with all its data intact.&lt;/p&gt;

&lt;p&gt;That alone is worth learning MVVM for.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Honest Truth About Getting Started
&lt;/h2&gt;

&lt;p&gt;You're not going to write perfect MVVM on your first try. I didn't. My first "MVVM" app still had logic leaking into the Activity in places. I used &lt;code&gt;LiveData&lt;/code&gt; wrong. My Repository was doing things it shouldn't.&lt;/p&gt;

&lt;p&gt;That's fine.&lt;/p&gt;

&lt;p&gt;The goal isn't perfection. The goal is to stop putting everything in one place. Even a messy, imperfect separation of concerns is infinitely better than a 700-line Activity.&lt;/p&gt;

&lt;p&gt;Start on your next project. Even a small one. Just ask yourself before writing anything: &lt;em&gt;does this belong in the View, the ViewModel, or the Model?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That question alone will change how you write code.&lt;/p&gt;

</description>
      <category>android</category>
      <category>architecture</category>
      <category>beginners</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>5 Things I Wish I Knew Before Writing My First Android App</title>
      <dc:creator>Aalaa Fahiem </dc:creator>
      <pubDate>Fri, 03 Apr 2026 14:06:48 +0000</pubDate>
      <link>https://forem.com/itsaalaa7/5-things-i-wish-i-knew-before-writing-my-first-android-app-41ki</link>
      <guid>https://forem.com/itsaalaa7/5-things-i-wish-i-knew-before-writing-my-first-android-app-41ki</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article is for beginners building their first Android app using Kotlin and Jetpack Compose.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I decided to build an Android app. How hard could it be, right?&lt;/p&gt;

&lt;p&gt;Turns out — pretty hard. Not impossible, but full of surprises that nobody warns you about. I'm still learning, but I've already collected a solid list of "why didn't anyone tell me this?" moments. Here are the five biggest ones.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Architecture Isn't Just for Big Projects
&lt;/h2&gt;

&lt;p&gt;When I started, I threw everything into one file. Logic, UI, data fetching — all living together in one giant &lt;code&gt;MainActivity.kt&lt;/code&gt;. It worked… until it didn't.&lt;/p&gt;

&lt;p&gt;The moment I needed to change something, I'd break something else. I had no idea what &lt;strong&gt;MVVM (Model-View-ViewModel)&lt;/strong&gt; was, and honestly the name scared me off.&lt;/p&gt;

&lt;p&gt;Here's what I wish someone had told me earlier:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Architecture isn't about being fancy. It's about not hating your own code two weeks later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Even for a small app, separating your UI (the View) from your logic (the ViewModel) makes everything easier to read, test, and fix. Start with MVVM from day one. Android Jetpack's &lt;code&gt;ViewModel&lt;/code&gt; and  &lt;code&gt;StateFlow&lt;/code&gt;  are built for this — don't ignore them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Before writing a single line of UI code, ask yourself: &lt;em&gt;where will the logic for this live?&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Android Will Destroy and Recreate Your Activity — Deal With It
&lt;/h2&gt;

&lt;p&gt;This one got me bad.&lt;/p&gt;

&lt;p&gt;I had a form where users filled in their details. When I rotated the phone, &lt;em&gt;everything disappeared&lt;/em&gt;. I panicked. I thought I had a bug. I didn't — that's just Android doing its thing.&lt;/p&gt;

&lt;p&gt;Android &lt;strong&gt;destroys and recreates your Activity&lt;/strong&gt; on configuration changes (like rotation, language change, or dark mode toggle). If you don't handle this, your app loses all its state every time.&lt;/p&gt;

&lt;p&gt;The fix? Use a &lt;code&gt;ViewModel&lt;/code&gt; — it survives configuration changes. Or use &lt;code&gt;rememberSaveable&lt;/code&gt; if you're on Jetpack Compose. Either way, don't store important state directly in your Activity or Fragment and expect it to stick around.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;ExampleScreen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MyViewModel&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;state&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uiState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; The Android lifecycle is not your enemy, but it will punish you if you ignore it.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Android Studio and Gradle Will Humble You
&lt;/h2&gt;

&lt;p&gt;I expected a smooth coding experience. What I got instead was:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gradle syncing for 4 minutes&lt;/li&gt;
&lt;li&gt;Mysterious build errors with no helpful message&lt;/li&gt;
&lt;li&gt;"Invalidate Caches and Restart" becoming my most-used button&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Android Studio is powerful, but it's heavy. Here's what actually helped me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep Gradle and your dependencies updated&lt;/strong&gt;, but not blindly — always check the changelog before upgrading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Learn the difference&lt;/strong&gt; between &lt;code&gt;implementation&lt;/code&gt;, &lt;code&gt;api&lt;/code&gt;, and &lt;code&gt;testImplementation&lt;/code&gt; in your &lt;code&gt;build.gradle&lt;/code&gt;. It matters.&lt;/li&gt;
&lt;li&gt;When something breaks and you don't know why: clean the project (&lt;code&gt;Build → Clean Project&lt;/code&gt;), then rebuild. Fixes more than it should.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Logcat&lt;/strong&gt; panel is your best friend. Filter by your app's package name and read the errors carefully — they're usually telling you exactly what's wrong.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Gradle is not magic. Learn the basics of how it works and you'll save yourself hours of frustration.&lt;/p&gt;




&lt;h2&gt;
  
  
  4.  AI Agents Are Powerful — But They Can Quietly Mislead You
&lt;/h2&gt;

&lt;p&gt;When I got stuck, I started asking AI assistants (like ChatGPT or Claude) for help. And honestly? They're incredible. They explain errors in plain English, suggest fixes instantly, and can write boilerplate code in seconds.&lt;/p&gt;

&lt;p&gt;But there's a trap I fell into: &lt;strong&gt;trusting AI output without questioning it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI agents don't always know the latest Android APIs. They can confidently suggest a method that was deprecated two versions ago, or generate code that compiles fine but behaves incorrectly at runtime. The code &lt;em&gt;looks&lt;/em&gt; right — that's what makes it dangerous for beginners.&lt;/p&gt;

&lt;p&gt;Here's how I learned to use AI tools better:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Always ask it to explain the code&lt;/strong&gt;, not just give it to you. If it can't explain a line clearly, that's a red flag.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-check with the official Android docs.&lt;/strong&gt; AI is a great starting point, not the final word.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tell it your context&lt;/strong&gt; — your API level, whether you're using Compose or XML, Kotlin or Java. Vague questions get vague answers.&lt;/li&gt;
&lt;li&gt;If something feels off about the generated code, &lt;strong&gt;trust that feeling&lt;/strong&gt; and dig deeper.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI is like a very fast, very confident pair programmer who sometimes hallucinates. Use it, but stay in the driver's seat.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; AI agents can save you hours — but only if you understand what they're giving you.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Performance Problems Are Invisible Until They're Not
&lt;/h2&gt;

&lt;p&gt;My first app felt fine on my phone. Then I tested it on an older device and it was &lt;em&gt;sluggish&lt;/em&gt;. Scrolling lists stuttered. The UI froze when loading data.&lt;/p&gt;

&lt;p&gt;Two things caused most of my problems:&lt;/p&gt;

&lt;p&gt;. &lt;strong&gt;Doing heavy work on the main thread.&lt;/strong&gt; Network calls, database reads, file operations — none of these belong on the UI thread. Use coroutines (&lt;code&gt;viewModelScope.launch { }&lt;/code&gt;) &lt;br&gt;
to move work to the background. It's easier than it sounds.&lt;/p&gt;

&lt;p&gt;You don't need to be a performance expert from day one. But knowing &lt;em&gt;that&lt;/em&gt; these issues exist means you can avoid the worst of them early.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Run your app on a low-end device or emulator occasionally. It'll reveal problems your flagship phone hides.&lt;/p&gt;




&lt;p&gt;Android development has a steep learning curve, and that's okay. Every confusing error message, every configuration change crash, every Gradle failure — it's all part of learning how the platform works.&lt;/p&gt;

&lt;p&gt;If you're just starting out: focus on fundamentals, not features.&lt;/p&gt;

&lt;p&gt;Build small. Break things. Learn why they broke.&lt;/p&gt;

&lt;p&gt;That’s how you actually improve.&lt;/p&gt;

&lt;p&gt;Still learning. Still building. Let me know in the comments if any of these hit close to home — or if there's something &lt;em&gt;you&lt;/em&gt; wish you'd known sooner! &lt;/p&gt;

</description>
      <category>android</category>
      <category>architecture</category>
      <category>beginners</category>
      <category>kotlin</category>
    </item>
  </channel>
</rss>
