<?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 AbdAllah Abd-El-Fattah on Medium]]></title>
        <description><![CDATA[Stories by AbdAllah Abd-El-Fattah on Medium]]></description>
        <link>https://medium.com/@abdallah.boda13?source=rss-8fbda176333------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*92-vYXQmg_J91Kl7_YjYmQ.jpeg</url>
            <title>Stories by AbdAllah Abd-El-Fattah on Medium</title>
            <link>https://medium.com/@abdallah.boda13?source=rss-8fbda176333------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 05:01:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abdallah.boda13/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[Clean Architecture in Android: Practical Guide.]]></title>
            <link>https://medium.com/the-d/clean-architecture-in-android-practical-guide-88095f7c2660?source=rss-8fbda176333------2</link>
            <guid isPermaLink="false">https://medium.com/p/88095f7c2660</guid>
            <category><![CDATA[architecture-components]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[AbdAllah Abd-El-Fattah]]></dc:creator>
            <pubDate>Sat, 09 Mar 2019 12:31:19 GMT</pubDate>
            <atom:updated>2019-03-09T12:31:19.945Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4I5v8JdS6r7izzxM" /><figcaption>Photo by <a href="https://unsplash.com/@philberndt?utm_source=medium&amp;utm_medium=referral">Philipp Berndt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A couple of weeks ago I attended an awesome talk given by <a href="https://medium.com/u/60d1226eade7">Ahmed Adel</a> and organized by the nice people at Tafra. It was about the clean architecture in Android and how to organize your codebase more efficiently.</p><p>Being the architecture fan I am, I decided to play around for a bit aiming to build a sample illustrating some of the main concepts we talked about in this talk.</p><p>And what came out of this attempt is <a href="https://github.com/AbdAllahAbdElFattah13/clean-rss-fiveagency">this lovely small — yet organized :D — repo</a>.</p><p>This repo represents an RSS-feeds app, that gives you the ability to add some your favorite feeds and enjoy reading articles provided by those feeds. For now, it only supports adding the feeds URL and removing them.</p><p>The purpose of this article is to go over the repo very quickly and touch on a couple of its different aspects and in each aspect, I’ll provide the main resources that help out during my work. I guess you can consider this article as some un-official documentation for the repo so far.</p><p>So without further ado, let’s dive in.</p><h4><strong>Clean architecture pattern</strong></h4><p>So this is not my first attempt to go for clean architecture, but what made this time kinda special is that I got the exchange some ideas about it with other fellow Androidguys, leading to more synthetic ideas about the famous architecture pattern. But it’s my first time attempting a separate module-per-layer and I got to say, it was something else. I really liked how each separate module represented a separate layer of the app. And the main source of attraction was the fact that the domain layer was completely Android-free in order to ensure that this layer would care about nothing other than the business logic for the app. That’s also why I created it as Kotlin-module, not Android module.</p><p>The main resource was <a href="https://five.agency/android-architecture-part-1-every-new-beginning-is-hard/">this series of articles</a> by five agency. Also, I love <a href="https://proandroiddev.com/clean-architecture-data-flow-dependency-rule-615ffdd79e29">this medium story</a> which talks about how the communication between the layers should go despite the fact that the outer layers should know about the inner layers but not vice-versa, it was a really nice way to describe it.</p><p>And finally, <a href="https://github.com/ahmed-adel-said/clean-movie-sample-app">This repo</a> — which was provided by Ahmed to illustrate what he was talking about — was nice to get some inspiration from.</p><h4><strong>RxJava</strong></h4><p>This repo was also a nice chance for me to test out the Reactive programming using RxJava for the first time in a practical project, I used <a href="https://medium.com/@qingzhong/rxjava-for-100-beginners-part-1-1ab9081f2a34">this series</a> to give me a jump start in the RxJava world. Can’t say I know much of it as of now, but for the very least I’m comfortable using it to connect the layers together up until the presentation layer was the liveData will take over.</p><h4><strong>View Model &amp; LiveData combo</strong></h4><p>For the presentation/ui modules, I’ve used ViewModel to help out with the app maintain its states over configuration changes. Also, LiveData provides nice auto-unsubscription when its lifeCycleOwner goes off the active state. And of course, we should dispose of any subscription in the ViewModel onCleared methods. If you want to know a bit more about LiveData and ViewModel history <a href="https://medium.com/the-d/google-android-architecture-components-97f11f8a9638">I’ve written a piece about that a while ago</a>.</p><h4><strong>Androidx</strong></h4><p>As most of you probably know by now, Google will stop updating the support libs after Android 9, and we’re now recommended to switch over to the unified Androidx packages, as use it for any new projects. So I did in this small repo.</p><p>The main thing to remember here is not to mix your dependencies and your XML tags, ex: using the Androidx dependency but still using the old support packages for the XML.</p><h4><strong>Material design</strong></h4><p>If you have used the Material Components for Android before, you probably know that they can be accessed using Android design support libs, but this is not the case anymore. If you’re using Androidx and want to use the Material Components then you should access them from Google’s Maven repository using “com.google.android.material” artifact.</p><p>As it was the case for the Androidx packages, make sure not to mix the packages of the old design lib and the new “com.google.android.material” libs, I found <a href="https://www.yudiz.com/introduction-to-upcoming-androidx-with-material-components/">this article</a> to be useful in this process.</p><h4>ListAdapter</h4><p>This <a href="https://developer.android.com/reference/android/support/v7/recyclerview/extensions/ListAdapter">ListAdapter</a> adapter allows you to compute the difference between two data sets off the main thread, and It will automatically dispatch the corresponding actions (notifyItemChanged, notifyItemInserted, notifyItemRemoved) instead of calling notifyDataSetChanged and rebinding the whole recycler view. That will give some nice animations for free, aside from the fact that it’s super important from a performance point of view.</p><p>I’m not gonna talk about it much because I’m planning on writing about this adapter a stand-alone article soon, so stay tuned. :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*fE2_Yx5OzvQ6JrSvb5XhQA.gif" /></figure><h4>Now what?</h4><p>My next move would be to add some test coverage to the app. Also to replace the current dependency injections static classes with Dagger 2, I’ve never tried Dagger 2 in a multi-module app setup.</p><p><strong>Enjoy! :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88095f7c2660" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-d/clean-architecture-in-android-practical-guide-88095f7c2660">Clean Architecture in Android: Practical Guide.</a> was originally published in <a href="https://medium.com/the-d">The D.</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[And then Google said: “Let there be guidance!”]]></title>
            <link>https://medium.com/the-d/google-android-architecture-components-97f11f8a9638?source=rss-8fbda176333------2</link>
            <guid isPermaLink="false">https://medium.com/p/97f11f8a9638</guid>
            <category><![CDATA[architecture-components]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-architecture]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[AbdAllah Abd-El-Fattah]]></dc:creator>
            <pubDate>Wed, 19 Dec 2018 17:57:26 GMT</pubDate>
            <atom:updated>2018-12-19T17:57:26.711Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://medium.com/the-d/hello-medium-656199a388a">Hello, Medium community! We are The D.</a> and with this first piece, we are introducing a series of articles that will each be written by our teammates within their areas of expertise.<br>So look out for future posts about AI, cybersecurity, iOS, programming, design and much more! Meanwhile, <a href="https://www.instagram.com/thed.gmbh/">meet the rest of the team here.</a><br>At the bottom of this article, you may also find a short bio of Abdallah, author of this story and our Senior Android developer.</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FSKGo6OYe24EBG%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FSKGo6OYe24EBG%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbGl0aXF1Z3oybTh6emx0amowOGR5MTd1YTlieGY3bDh5NGxrNzJxbSZlcD12MV9naWZzX2dpZklkJmN0PWc%2FSKGo6OYe24EBG%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="313" frameborder="0" scrolling="no"><a href="https://medium.com/media/acfcf2b3afcf895afe673a2d65bf6645/href">https://medium.com/media/acfcf2b3afcf895afe673a2d65bf6645/href</a></iframe><p>I suppose that you — as an Android geek — have already heard about the <em>“Android Architecture Components”</em> presented by Google during Google IO’17 last year.</p><p>However, if for some mystery reason this is your first time hearing about them, then don’t worry — I got you covered!</p><h3>The “not so old” times:</h3><p>For so many years (9 to be exact), the Android platform team didn’t care about how you wrote Android application code!</p><p>Yes, <strong>they didn’t care</strong>. Most importantly they admitted it publicly. In a famous <a href="https://plus.google.com/+DianneHackborn/posts/FXCCYxepsDU">Google+ post</a>, Dianne Hackborn — the one who architected the Android platform in its early days — stated that one should not think about the Android platform as an application framework, but more of a “system framework”, a framework that is more sophisticated/rich than just a plain operation system, but at the same time, doesn’t tell you anything about your app internals.</p><p>Basically the Android framework — and hence its team — considered its only responsibility to be handling the communication between an app and the underlying OS. <strong>The communications, only the communications, and nothing but the communications</strong>.</p><p>So once the app starts — i.e an activity starts — you are on your own my friend. Follow your instinct, fly to the moon, organize your code-base the way you want, or even don’t. <strong>They. Don’t. Care.</strong></p><p>This lack of guidance from Google’s side was reflected in so many ways, for example, one could find tons of code lines which are responsible for the business logic written in the activity itself, leading to all sort of errors that one can think about — from tiny issues to memory leaks. Not to mention the lack of testability and separation of concerns.</p><p>And even when the team introduced the Fragments framework back in Android 3.0, they introduced it with the same mindset.</p><p>But in my own opinion, the main three issues regarding this whole thing are:</p><h4>1. The lifecycle problem(s).</h4><p>The lifecycle of any given app — from an app developers perspective — should be as straight as [start, run code, finish] and that is about it! But with the Android platform you have a lot — and I mean <strong>a</strong> <strong>lot</strong> — more than this.</p><p>For example you can have an activity that is started, but not visible fully to the user, and you can also have an activity that is stopped but not fully destroyed, not to mention that you can — since you don’t really isolate your code — have this zombie activity that is finished but yet can’t be released from memory — laying around, eating your device battery. Throw in a couple of fragments in this activity with their own lifecycle and it will be really (and I mean <a href="https://i.stack.imgur.com/1llRw.png">really</a>) ugly.</p><p>This lifecycle handling was one of the hardest challenges facing anyone who wrote Android apps and at the same time the <strong>FIRST </strong>problem that one had to find a solution for, because after all — if you didn’t get it right, your app — simply — would not work properly!</p><p>Now to be fair, the lifecycle events are really important from the system point of view, due to the nature of mobile devices: As an example you can be viewing your social feeds when suddenly you receive a call — in this situation the system needs to have the power to “pause” and “resume” your app in a way that is transparent for the user himself, no doubt about that.</p><p>Oh, and don’t forget that most of the components that handle the interaction with the hardware in the Android system need to know about the lifecycle as well, which means that your activity/fragment needs to babysit them by passing the needed lifecycle event — that you get from the activity/fragment classes — to components that need those lifecycle events. So even if your activity/fragment doesn’t need the lifecycle events, it still has to override the lifecycle methods only to pass them to whatever components need them. This will quickly grow to a mess, having those 20-something onStart() and onStop() methods in your activity/fragment which don’t provide any added value for your app itself, just babysitting the other components.</p><p>But the point is, if — almost — every app will face those problems, then why should <strong>every app </strong>attempt to solve them? Why do we have to re-fix them with each new app? Shouldn’t we be given a standard way to solve this, at least?</p><h4>2. The growth of bad habits</h4><p>By a show of hand — let’s see who has ever written all of his app logic into the activities/fragments of his app?</p><p>Come on, no shame in it, we all have done it once or twice, some more than others, some still convinced that this is the only way to do things.</p><blockquote><strong>Those were the dark ages for Android development.</strong></blockquote><p>During such moments, when you find yourself responsible for refactoring an app that has been built in such a way, you start asking yourself one question: How did we end up here?</p><p>Simple answer: <strong>lack guidance</strong>.</p><p>When you are working on a platform backed by a giant tech lead like Google, you can expect a certain level of guidance to be provided. When/if you don’t find such guidance, you start thinking that all is allowed unless stated otherwise, and that’s exactly when everything starts flying out of the window.</p><p>There’s a set of software engineering principles that you’d better adhere to. If you decided to customize them as per your domain/needs, then that is totally fine — as they’re not your holy book after all (even if you decided to break some of them for some — hopefully — good reasons), but you can’t just simply ignore all of them at once and hope that everything will *magically* be OK!</p><p>Principles, such as the Single responsibility principle, interface segregation principle, dependency inversion principle, etc.. should be your guidance even if you’re missing it from Google in the first place.</p><p>Don’t get me wrong, I’m not saying you <strong>MUST</strong> adhere to them. I’m saying that unless you have good reasons not to — and 90% you actually don’t — you <strong>SHOULD </strong>adhere to them to make your life — and your fellow devs — easier.</p><p>Now, back to the all-code-in-activities-fragments way of doing things. When you do such things, you end up with a very fat activity, meaning that your business logic can’t be tested efficiently nor can it be reused in any other place in your app, and even worse, you end up with a <a href="https://en.wikipedia.org/wiki/God_object">GOD object</a> that does everything at the same time, which makes adding new features to your app much harder because any change you do will break some other feature, and, additionally, you can’t do proper fixes as well [Sounds familiar?].</p><p>This Is a totally bad programming habit for all the reasons in the world, including your own health. No doubt about that.</p><p>Now imagine the following: What if — for some mysterious reason — the tech giant that supports the platform itself, the mighty GOOGLE, said that this is — indeed — a bad habit? And that you should move your app logic outside of the activities/fragments?</p><p>Just imagine if that happened, how many of us — the devs/sw engineers — would continue going with this old bad habit? I’m not saying that none of us would stop using it overnight, but still, this habit would decrease dramatically.</p><p>If you can’t imagine it, no need, it did happen in IO’17. :)</p><h4>3. Application developers fight and newcomers get lost in the middle.</h4><p>Now since we agreed that writing code in the activity/fragment is a very bad habit, we need to find a better way, and finding that other “better way” should be fairly simple “given the same set of principles”, right?</p><p>Well, you would think! But we — as a dev community — love to argue over the simple stuff, I mean you know about the famous <a href="https://www.reddit.com/r/ProgrammerHumor/comments/8s96kl/tabs_vs_spaces/">spaces vs tabs war</a>, right?</p><p>So just like that, the Android dev community started its own war, between the MVC, MVP (both passive view and supervising controller) and MVVM, all the way to the new MVi (seriously, there’s such a thing, just google it) and the clean architecture. Everyone adapted a situation and decided that their way is the best and everyone else should follow them, while in fact, none of those architecture patterns were perfect for all use cases (it’s “it depends” kinda situation). It was quite a mess for a while.</p><p>And the thing is that the architecture discussion doesn’t have a silver bullet to finish it off, as a matter of fact, it has a lot of factors that range between personal preferences all the way to the different nature of apps we build, so this “discussion” will most likely be going to last forever and ever with nothing that can be done to stop it.</p><p>Now let’s assume you’re a new Android dev who just started writing Android apps, and you’ve just found out that it’s not very flexible to write all of your code in the activities/fragments of your apps, and you’re looking for a better path. You started to search around and you found not one or two, but tons of articles claiming that they are doing the right thing, although they are doing it in very different ways!</p><p>You’re confused, you’re frustrated, you adapted one architecture pattern, and in the middle of the process you switched to another, then added a 3rd party library that’s actually more convenient to a third architecture pattern et voilà: you created a Frankenstein monster all over the place, so you’re right where you started: an app that can’t be extended nor maintained. So — as a result — you abandon all of your software engineering beliefs and go back to your old — still very bad — habits.</p><p>Now to the question: what caused the whole thing?</p><p>Again: <strong>Lack of guidance</strong>.</p><p>If the majority of the community did agree on an architecture pattern that is more suitable for <strong>MOST </strong>of the use cases, then this young Android poor dev could’ve just started with this architecture pattern as a guideline, and as he grows older, wiser and more experienced, he would understand the tradeoffs between the different architecture patterns, and could then accordingly choose for himself. But, as a beginner, he can’t make such a decision. Simply because he doesn’t understand their tradeoffs.</p><h4>The Android community needed more mentorship.</h4><p>And again, this is exactly what happened at Google IO’ 17.</p><h3>And then Google said: “Let there be guidance”</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UBv9Vjm65hEw1gZQ5yegQA.jpeg" /></figure><p>At Google IO’ 17, all of the voices of the Android dev community were finally heard, and Google decided to publish mainly 3 important things to help out with the above-mentioned issues. [We will discuss them briefly here, but actually, each of them needs its own article for the least. :) ]</p><ul><li><strong>The lifecycle objects and lifecycle-aware observables:</strong></li></ul><p>The first thing that they did was to try to address the lifecycle issue. How so, you ask? They introduced three very important concepts: lifecycle observer, lifecycle owner, and lifecycle object.</p><p>What’s the lifecycle observer? It’s an object that wants to be notified when a lifecycle owner changes its state. It will have hooks to the lifecycle events sent to it to be able to react accordingly if needed.</p><p>What’s the lifecycle owner? It’s a “thing” that has a lifecycle, it can be literally anything that needs to have a lifecycle of its own, and starting from API 28 the support activity/fragment implement this one method <a href="https://developer.android.com/reference/android/arch/lifecycle/LifecycleOwner">interface</a>, but It doesn’t have to be an activity or a fragment, any class implements this interface is-a lifecycle owner.</p><p>What this means is that you don’t need necessarily an activity/fragment to use, you just need a lifecycle owner. This decoupling is usually preferred, and once you define which lifecycle owner you are interested in, you can start to observe it. It doesn’t need a fragment or an activity babysitting those components anymore only to send it the lifecycle events.</p><ul><li><strong>A lightweight ViewModel class:</strong><br>Remember the doing-everything activity/fragment? Now we are encouraged to move all of the business logic related to the code outside of the UI controllers “the activity/fragment new name”, so for starters, you can move all your data fields to a ViewModel to keep them for you. The interesting thing is that the ViewModel classes are not really SDK dependant, and thus the “lightweight” prefix in the title, meaning it can be tested locally on the JVM, without the need for the SDK itself.<br>And if that’s not enough for you, you also need to know that the ViewModel is preserved across configuration changes, meaning it has a <a href="https://developer.android.com/images/topic/libraries/architecture/viewmodel-lifecycle.png">different/simpler lifecycle</a>. For this exact reason, the ViewModel classes MUST not reference a view, LifeCycle, or any class that may hold a reference to the activity context. Think about them as a store to the UI related data that will be used from the UI controllers.</li><li><strong>Lifecycle-aware data holder observable:</strong><br>Building on top of the lifecycle-aware components, the Android team introduced the LiveData class, which allows you to observe it from any lifecycle owner, and it will notify this lifecycle owner with its current data, if any, as well as any updates happening while the lifecycle owner is in an active state “either started or resumed”.</li><li>In case you didn’t notice it yet, the <strong>LiveData addition goes very nicely with the ViewModels</strong>, so by keeping your LiveData objects in a ViewModel object, and because the ViewModel survives through configuration changes the newly created UI controller will receive the same data that was being displayed in the destroyed one once the newly created UI controller subscribes to the LiveData object it needs, and on the other side — because it is Lifecycle-aware — the LiveData will handle the unsubscription on your behalf at the right time for free. Which means fewer memory leaks, and less zombie UI controllers hanging around, and I don’t think anyone will miss them actually.</li></ul><h4>Guide to app architecture</h4><p>The wait is over, Google finally released an opinionated guide — that’s what the internal team called it for a while — regarding the app architecture in Android!<br>Yes, it’s not new. Yes, a lot of people have been using it for a while [it’s MVVM based architecture with a repository after all]. But it services like an entry point for anyone who wants to understand more about how to architect their Android app better. A good move in the right direction. And the most important thing is that they are actually using all of the above stuff throughout the guide itself, which is super cool because it feels nice that they are building something that’s really coherent and thought through.</p><p>You can read more about the <a href="https://developer.android.com/jetpack/docs/guide">guide</a> if you like, we’re planning to have some upcoming articles addressing the main components of those releases with more depth and examples.</p><p>Again, it’s really nice to see this move from Google’s side, this kind of support, this level of working with, and for the community. Let’s hope it lasts. :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*wLSSNmnyivIWitfvRTDk-g.jpeg" /></figure><p><a href="https://www.instagram.com/p/BizJpToBr_T/">Abdallah</a> is a Software Engineer at The D.. He’s interested in app architecture &amp; loves to keep up with new technologies as they emerge.<br>Currently, he works mainly with native Android projects in Kotlin.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97f11f8a9638" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-d/google-android-architecture-components-97f11f8a9638">And then Google said: “Let there be guidance!”</a> was originally published in <a href="https://medium.com/the-d">The D.</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>