<?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 Chadi Abidi on Medium]]></title>
        <description><![CDATA[Stories by Chadi Abidi on Medium]]></description>
        <link>https://medium.com/@shadyabidi?source=rss-85d39f0d2280------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*uxf_QOyQumCWDGfW.</url>
            <title>Stories by Chadi Abidi on Medium</title>
            <link>https://medium.com/@shadyabidi?source=rss-85d39f0d2280------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:04:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shadyabidi/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[Android architecture: What if your app only has one screen?]]></title>
            <link>https://medium.com/tech-blog-door2door/android-architecture-what-if-your-app-only-has-one-screen-62a8051be7e6?source=rss-85d39f0d2280------2</link>
            <guid isPermaLink="false">https://medium.com/p/62a8051be7e6</guid>
            <category><![CDATA[android-mvp]]></category>
            <category><![CDATA[android-architecture]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Chadi Abidi]]></dc:creator>
            <pubDate>Wed, 25 Jul 2018 10:07:26 GMT</pubDate>
            <atom:updated>2018-07-25T10:16:20.354Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing high-quality apps can be difficult and complex. It isn’t just about fulfilling prerequisites and requirements — the app should also be robust, functional, testable, and sufficiently adaptable to development and change.</p><p>This is where “clean architecture” becomes an important approach to building any app.</p><p>Clean architecture is a set of best practices and rules which deliver frameworks that are:</p><ul><li>Independent of the user interface.</li><li>Testable.</li><li>Separated from the database (data layer).</li><li>Free of any external dependencies.</li></ul><blockquote><em>“The only way to make the deadline — the only way to go fast — is to keep the code as clean as possible at all times.”</em></blockquote><p><strong><em>— Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship</em></strong></p><p>The problem with Android out of the box is that activities are tightly coupled with views and data access objects, which can make testing a nightmare. This dramatically increases the complexity of the code, making it hard to maintain and extremely difficult to scale, since every new feature will require you to rewrite other functionality.</p><p>Developers have tackled these issues for decades through the introduction of design patterns.</p><p>Design patterns serve as a template for building production software with decoupled components.</p><p>The MVP (Model-View-Presenter) pattern allows us to separate the presentation layer from the view, making it easy to add new functionality without refactoring unrelated components.</p><p>MVP makes it easier to test functionality as units, since every new piece of functionality will have its own presenter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*Y4SH5v31efe6Tir8XV-kPg.png" /></figure><p><strong>Presenter</strong>: The Presenter is the layer that handles the business logic and the usability of the feature. It receives ViewModels (use cases) from the data layer and orchestrates how this data should be presented to the View.</p><p><strong>View</strong>: The View is the layer that acts as a bridge between the UI and Presenter. In general, it is implemented by system classes (e.g. Activities or Fragments). It knows about the existence of the Presenter and notifies it with view changes (a button click, for instance), and also executes instructions like rendering or updating UI components.</p><p><strong>Model</strong>: The Model is the object returned by the logic layer which fulfils the specific use case. Usually it is a ViewModel, which is passed to the Presenter to be handled and displayed in the UI by the View.</p><p>If the business logic depends on accessing the data layer, another level of abstraction is needed to make sure that the model presented to the Presenter implements the specific use case it is meant to solve:</p><p><strong>Interactor</strong>: The Interactor is the object responsible for retrieving the data coming from the data layer (e.g. external API or internal database), and passing the data to different Presenters. The interactor uses Helper classes to transform the data models into ViewModels specific to each use case.</p><p><strong>Mapper</strong>: Mappers are the classes that are responsible for transforming data models to ViewModels. The Interactor asks the the data layer for data, maps it into a ViewModel, then forwards it to the Presenter.</p><blockquote>“If you think good architecture is expensive, try bad architecture.”</blockquote><p><strong>— Brian Foote</strong></p><p>The business logic layer that we have been discussing is where all the magic happens. It is where we solve the problem our app is designed to solve. MVP as a design pattern allows us to ensure the highest quality code for our apps, and also give them a long life span, making them maintainable and sustainable.</p><p>The business layer is totally separated from the system layer, which includes all the Android-specific frameworks (such as Activities, Fragments, Views and Buttons) through interfaces.</p><p>This separation allows us to develop our logic without any system interferences, making our code highly testable and easy to work with, and allowing us to run our tests without the need for an emulator. This is quite powerful, especially when every Activity or Fragment in the app is its own feature and exists independently from other Activities and Fragments.</p><p>But what if one single screen has independent features? This requires each one of them to have its own business logic layer.</p><p>What if the screens are dependent on each other or share functionality?</p><p>How would Presenters communicate with each other whilst remaining independent?</p><p>How can we orchestrate communication or navigation between features?</p><h3><strong>What if the whole app is one single screen?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*EQRvjRDWHUVaIQED_DAPTQ.gif" /></figure><p>We recently launched a new version of our <a href="https://play.google.com/store/apps/details?id=io.door2door.drt">allygator app</a>.</p><p>Since we are a mobility company specialized in ridesharing and public transport systems, our apps rely heavily on maps.</p><p>Right from the start, we wanted the app to be a single screen (“Activity”) that displays the map, with features coming in and out of view and details updated on the main map with polylines and markers. This way, we avoid duplicating the maps across screens and interrupting the user experience when the map is reloaded every time a new feature comes into focus.</p><p>The MVP pattern alone is not enough for this challenging task. We wanted a component that existed in the presentation layer yet was independent from the data layers, one that could also handle communication between Presenters.</p><p>For example, every time we show a route in a list, we need to update the map to show the corresponding polylines.</p><p>In this case, the component will get a notification from the ListPresenter that the Route Item is in focus, and the component will ask the MapPresenter to show the corresponding polyline.</p><p>In addition to handling UI events, the component is responsible for holding the stack of displayed features and handling the logic of transitions between them, making sure that this does not result in unexpected side effects or unwanted behaviors.</p><p>In our app, we called this new component the “Router”. Single-page web applications have been using this concept for years.</p><p>Developers favor this method over the manual handling of navigation between views because:</p><ul><li>Routers are declarative, so you can quickly observe which screens your application has and which parameters are passed between them.</li><li>Routers keep your UI in sync with the API reactively. If you update a Presenter, other Presenters will be refreshed automatically. We find a ‘reactive’ pattern much better for front-end applications than a ‘proactive’ approach. This is why a lot of front-end developers love React.js, RxJava, Anvil and many others.</li><li>Testing the Router ensures that communication and navigation between components is maintainable, and reduces the possibility of side effects (like two views being shown at the same time).This reduces the need for UI tests.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*QvcWqAIDMYqfJKg9S3CLlg.png" /></figure><p>Each Presenter gets the shared instance of the Router and sends an event whenever outside communication is needed.</p><p>The Router does not know about the existence of Presenters. It is only concerned with the navigation stack and processing calls that are required by the feature it is serving.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bNJOgOD_XrvrqQYYMv8JTw.png" /></figure><p>The Router is an essential component in enabling this architecture to work. Each Activity needs a Router to handle Presenters and oversee the back stack. Routers survive configuration changes, and they are kept in the memory until their host Activity is deliberately destroyed by users or engineers (e.g. by pressing the back button, calling onDestroy()…), or by the Android framework whilst recovering memory.</p><p>The navigation layer is especially important in an app that handles tablet mode — the only thing that may change is how the various Views are displayed. This allows your different layers to remain untouched, as the Router is in charge of the route flow for every form factor — regardless of phone or tablet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*D0mooD8bW9NPEqp_YVtSrg.gif" /></figure><h3>Is it worth it?</h3><p>It is difficult to say which approach to pick for any given situation. For me, the greatest advantage of having a single Activity in an Android application is that we maintain full control of what is happening in the application, particularly when we need to make animations between content views and keep the main screen in the background.</p><p>Given all that control you should normally invest more energy doing this in a way you like. You could also choose a blended approach, where a portion of the logic is in a different Activity (like forming an email). It’s all up to you!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*SL2K9IRDkj3HVoNjDJhAMQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62a8051be7e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-blog-door2door/android-architecture-what-if-your-app-only-has-one-screen-62a8051be7e6">Android architecture: What if your app only has one screen?</a> was originally published in <a href="https://medium.com/tech-blog-door2door">door2door Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>