<?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 Jorge Nicolás Nogueiras on Medium]]></title>
        <description><![CDATA[Stories by Jorge Nicolás Nogueiras on Medium]]></description>
        <link>https://medium.com/@nogueiras?source=rss-42aca0245b67------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xU8mPt6CP811Nur-si4fCA.jpeg</url>
            <title>Stories by Jorge Nicolás Nogueiras on Medium</title>
            <link>https://medium.com/@nogueiras?source=rss-42aca0245b67------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:04:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nogueiras/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[A ViewModel to keep them all]]></title>
            <link>https://nogueiras.medium.com/a-viewmodel-to-keep-them-all-e68b4ae40aa3?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/e68b4ae40aa3</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[viewmodel]]></category>
            <category><![CDATA[jetpack]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Sat, 15 Aug 2020 22:43:27 GMT</pubDate>
            <atom:updated>2020-08-15T22:43:27.843Z</atom:updated>
            <content:encoded><![CDATA[<p>If you thought you couldn’t squeeze your <strong>ViewModels</strong> any more, here we will talk about how and what else you can do with them using <strong>SavedState</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1bnRBQNl4sqCNtc_i-5jZQ.jpeg" /><figcaption><a href="https://lotr.fandom.com/wiki/One_Ring">https://lotr.fandom.com/wiki/One_Ring</a></figcaption></figure><p>The last few years have been, for all Android developers, endless emotions. The advances that have been made, the number of new libraries, improvements, and changes not only appreciative but also with performance in the platform have excited everyone. Among all these advances and improvements, the incorporation and classification of libraries within <a href="https://developer.android.com/jetpack">Android Jetpack</a> are, in my opinion, the best.</p><p>Although these libraries continue to advance and some others are being incorporated — such as <a href="https://dagger.dev/hilt/"><strong>Hilt</strong></a> — , today we are going to concentrate on one in particular, the <a href="https://developer.android.com/topic/libraries/architecture/viewmodel"><strong>ViewModels</strong></a>. These, in combination with <a href="https://developer.android.com/topic/libraries/architecture/livedata"><strong>LiveData</strong></a>, give us a secure framework to implement — and why not migrate — our architecture to <strong>MVVM</strong>.</p><p>The particularity of the ViewModels as well as the recently released Hilt, has to do with what Google is betting for the present and the future of Android applications. They are <em>recommending</em> and <em>suggesting to us</em> that we use them, something that had never happened before and was a constant on other platforms.</p><p>Much has been said about the use of ViewModels, good and bad practices, their applications, recommendations, etc. However, there is one more thing we can do with them to extend their functionality and that is, keep information even when Android kills the process while our app is in the <em>background</em>; generally caused by <strong><em>low memory</em></strong>.</p><h3>SavedState</h3><p>It is already known that ViewModels have been designed to maintain the state of the UI when configuration changes occur. This avoids us having to make extra requests for information that we already had available, making the user wait, overloading our APIs, etc. Additionally, we have the callback onSavedInstanceState in our <em>activities/fragments</em> that allow us to save information that can be recovered even sometime after it has been destroyed <strong>by the system</strong>.</p><p>Perfect, it’s already solved. So why do we need <strong>SavedState</strong>? Well, let’s say that if we are going to persist some light-weight information that we need to survive the possible destruction of the Activity, it would be ideal to have everything <em>“in one place”</em>, so we don&#39;t have problems when it comes the time to look for it. Although the information “retention” cycles are different if we talk about LiveData’s and onSaveInstanceState, by having them separated we are delegating the responsibility of keeping our views up to date in both the ViewModel and the <em>activities/fragments</em> alike.</p><p><strong>SavedState</strong> comes in a way to cover this need to unify responsibilities. Let’s see what this is about.</p><h3>Configuration</h3><p>In order to work with SavedState, we need to include the dependency on <a href="https://developer.android.com/jetpack/androidx/releases/fragment"><strong>Fragments</strong></a> or <a href="https://developer.android.com/jetpack/androidx/releases/activity"><strong>Activities</strong></a> from <em>androidx</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89373c3214ce362492bbd3010c8c06db/href">https://medium.com/media/89373c3214ce362492bbd3010c8c06db/href</a></iframe><p>In this case, we are going to use the dependencies of <strong>Fragment</strong>, but we could have used <strong>Activities&#39; </strong>one<strong> </strong>and it would be the same.</p><blockquote>For older versions of these dependencies, you need to include the <a href="https://developer.android.com/jetpack/androidx/releases/lifecycle#declaring_dependencies"><strong>lifecycle-viewmodel-savedstate dependencies</strong></a>.</blockquote><p>Once the dependency is included, the <strong>ViewModels</strong> will have the possibility of receiving as a parameter a SavedStateHandle object that will be in charge of saving and returning information even in those cases where our process was terminated by the system.</p><p>We can make use of the viewModels delegate looking like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d041261d70a7f6ddde9a2f0a5a159f80/href">https://medium.com/media/d041261d70a7f6ddde9a2f0a5a159f80/href</a></iframe><p>Our final ViewModel will be like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bb995cd6b168110c6b4ae02f03c746b/href">https://medium.com/media/7bb995cd6b168110c6b4ae02f03c746b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a86772120029f31c08a74a048f552b5b/href">https://medium.com/media/a86772120029f31c08a74a048f552b5b/href</a></iframe><p>If we pay attention to our constructor, we are receiving the state object of type SavedStateHanlde. Through this, we can save and then access the data that we save there. Although we are saving an object of type Serializable, we can save <a href="https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate#acceptable-classes">other types of data</a> too.</p><p>One particularity of this object is that it allows us to obtain a value that we have previously saved through a <strong>LiveData</strong>. In the previous <em>snippet,</em> we can see how we recover the scroll position of a <strong>RecyclerView</strong> in case our process dies.</p><blockquote>Each of the views is capable of saving <strong>its own data</strong> in case of configuration changes, they can check that their recyclers and any other view maintains their information. Basically every view that contains an id implements its own onSaveInstanceState.</blockquote><p>We said that our object survives the process finalization by Android. Let’s see how to validate it using the project that I will leave at the end of the article.</p><p>Once the application is installed on our device (or using an emulator), we are going to recreate the process of destroying our Activity, so when recreating we should remain in the same state:</p><ol><li>We open the example app</li><li>We scrolled “a little”</li><li>We send the app to the <em>background</em>.</li><li>We search for the app using <strong>adb</strong> and kill it.</li><li>Upon returning to the app, we check that indeed our app was left with the recycler in the position where we left it.</li></ol><blockquote>To search for our app in the device processes we do <strong>adb shell ps -A | grep com.my-package</strong> and to end the process <strong>adb shell am kill com.my-package</strong></blockquote><p>If we have the developer options enabled on our devices, we can configure the <strong><em>Don’t keep activities</em></strong> option to emulate killing the process in case of changing <em>Activity</em> or sending it to the <em>background</em>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5VKbvrjxpVJCM%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2F5VKbvrjxpVJCM&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdmIzdTBiZjk1eGM1cWk5emNmNno3YmNweDRpb3lnNmZ1d3h0MHhzbiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F5VKbvrjxpVJCM%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="348" frameborder="0" scrolling="no"><a href="https://medium.com/media/44842cd3cbc9b58edacd7ca23fbbafb0/href">https://medium.com/media/44842cd3cbc9b58edacd7ca23fbbafb0/href</a></iframe><h4>Wait a minute… my ViewModels use Interactors</h4><p>Even if you are working with a particular architecture for your entire application, such as Clean Architecture or IDD, or you are doing unit testing on your ViewModels, it is necessary to inject other objects (dependencies) into them, so the use of the delegate the way we are already using it is not enough.</p><p>What we need is to tell our delegate what is the factory with which it has to build our ViewModel and in order to make use of <strong>SavedState</strong>, we have to extend the AbstractSavedStateViewModelFactory. In this way, we can build our ViewModel with all its dependencies and add the SavedStateHandle .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de7c63527588221727c64424e9b428f7/href">https://medium.com/media/de7c63527588221727c64424e9b428f7/href</a></iframe><p>From here we can identify some objects that are worth mentioning, to understand how the objective of preserving our data is achieved:</p><ul><li>SavedStateRegistryOwner: Basically what we need is some class that can handle a SavedStateRegistry. In our case, we have provided this because Fragment implements this interface.</li><li>AbstractSavedStateViewModelFactory receives a second parameter that we have set as null (optional actually) and allows us, in case of no previous state, to provide a Bundle with info by <em>default</em>.</li></ul><h4>Real-world use cases</h4><p>This implementation that we present is a mere example and perhaps not very useful and even trivial. The <em>recyclers</em>, like all the views to which we have indicated an id (identifier), are capable of saving their own state. However, <strong>SavedState</strong> can be a solution when it comes to avoiding crashes in complex flows, which require transitions between several fragments, such as login, purchase, survey loading, etc; where our app can go to the <em>background</em>, be destroyed by Android and when we return, we no longer have that necessary information that we thought we had secured, causing crashes in production, usability problems and, bad user experience which is even worse.</p><h3><strong>Conclusion</strong></h3><p>The ViewModel has been one of those architectural patterns that have come to stay for good (or at least for a while). They have managed to combine the <strong>MVVM</strong> pattern and the Android life-cycle in such a way that, when <strong>used properly</strong>, they allow us to obtain good results safely. <strong>SavedState</strong> as a compliment is simply more useful even for those occasions and contexts in which we need to go further, unifying responsibilities and ensuring that no matter what happens with our application in the <em>background</em>, the information will still be there.<br>Go ahead, give it a try!</p><p>You can find all the code used in the following repository:</p><p><a href="https://github.com/nogueirasjorge/saved-date-example">nogueirasjorge/saved-date-example</a></p><p>Stay in touch, @<a href="http://twitter.com/nogueirasjn">nogueirasjn</a> at 🐦.<br>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e68b4ae40aa3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Un ViewModel para guardarlos a todos]]></title>
            <link>https://medium.com/droid-latam/un-viewmodel-para-guardarlos-a-todos-9203ecc92b53?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/9203ecc92b53</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[viewmodel]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Sun, 19 Jul 2020 14:05:14 GMT</pubDate>
            <atom:updated>2020-08-17T14:36:14.934Z</atom:updated>
            <content:encoded><![CDATA[<p>Si pensabas que no podías exprimir más a tus <strong>ViewModels</strong>, aquí charlaremos sobre cómo y qué más puedes hacer con ellos usando <strong>SavedState.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G7xwXKKWZFLZlqnROVK4Tw.jpeg" /><figcaption><a href="https://lotr.fandom.com/wiki/One_Ring">https://lotr.fandom.com/wiki/One_Ring</a></figcaption></figure><p>Los últimos años han sido, para todos los desarrolladores Android, un sin fin de emociones. Los avances que se han hecho, la cantidad de librerías nuevas, mejoras y cambios no sólo estéticos sino de performance en la plataforma han entusiasmado a todos. Entre todos estos avances y mejoras, la incorporación y clasificación de librerías dentro de <a href="https://developer.android.com/jetpack">Android Jetpack</a>, es a mi entender, de lo mejor.</p><p>Si bien estas librerías continúan avanzando y se van incorporando algunas otras — como lo es <a href="https://dagger.dev/hilt/"><strong>Hilt</strong></a><strong> </strong>— ,<strong> </strong>hoy vamos a concentrarnos sobre una en particular, los <a href="https://developer.android.com/topic/libraries/architecture/viewmodel"><strong>ViewModels</strong></a><strong>.</strong> Éstos, en combinación con <a href="https://developer.android.com/topic/libraries/architecture/livedata"><strong>LiveData</strong></a>, nos dan un marco seguro para implementar — y por qué no migrar — nuestra arquitectura a <strong>MVVM</strong>.</p><p>La particularidad de los ViewModels así también como la recién salida Hilt, tiene que ver con lo que Google está apostando para el presente y el futuro de las aplicaciones Android. Nos han empezando a <em>recomendar - sugerir- </em>que las utilicemos, algo que nunca había ocurrido antes y sí era una constante en otras plataformas.</p><p>Se ha hablado bastante del uso de los ViewModels, las buenas y las malas prácticas, sus aplicaciones, recomendaciones, etc. Sin embargo, hay una cosa más que podemos hacer con ellos para extender su funcionalidad y es, mantener información aún cuando Android nos mata el proceso estando nuestra <em>app</em> en <em>background; </em>generalmente ocasionado por <strong><em>baja memoria (lowMemory).</em></strong></p><h3>SavedState</h3><p>Ya es sabido que los ViewModels<strong> </strong>han sido pensados para mantener el estado de la UI cuando se producen cambios de configuración. Esto nos evita tener que realizar pedidos extras por información que ya teníamos disponible, haciendo esperar al usuario, sobrecargando nuestras API, etc. Adicionalmente contamos con el callbackonSavedInstanceState en nuestros <em>activities/fragments</em> que nos permite guardar información que puede ser recuperada incluso un tiempo después de que ésta haya sido destruida <strong><em>por el sistema</em></strong>.</p><p>Perfecto, ya está resuelto. Entonces, ¿para qué necesitamos <strong>SavedState</strong>? Bueno, digamos que si vamos a persistir cierta información liviana que necesitamos sobreviva a la posible destrucción del <em>Activity </em>sería ideal tener todo &quot;en un mismo lugar&quot;, tal de no tener inconvenientes a la hora de dónde buscar qué cosa. Si bien los ciclos de &quot;retención&quot; de la información son distintos si hablamos de LiveData&#39;s y onSaveInstanceState, al tenerlos separados estamos delegando la responsabilidad de mantener nuestras vistas actualizadas tanto en el ViewModel como en los <em>activities/fragments</em> por igual.</p><p><strong>SavedState</strong> viene de cierto modo a cubrir esta necesidad de unificar responsabilidades. Veamos de qué se trata.</p><h4>Configuración</h4><p>Para poder trabajar con SavedState necesitamos incluír la dependencia de <a href="https://developer.android.com/jetpack/androidx/releases/fragment"><strong>Fragments</strong></a> o <a href="https://developer.android.com/jetpack/androidx/releases/activity"><strong>Activities</strong></a> de <em>androidx</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89373c3214ce362492bbd3010c8c06db/href">https://medium.com/media/89373c3214ce362492bbd3010c8c06db/href</a></iframe><p>En este caso vamos a usar las dependencias de <strong>Fragment</strong>, pero podríamos haber usado la de <strong>Activities</strong> y sería lo mismo.</p><blockquote>Para versiones anteriores de estas dependencias, es necesario incluír las dependencias de <a href="https://developer.android.com/jetpack/androidx/releases/lifecycle#declaring_dependencies"><strong>lifecycle-viewmodel-savedstate</strong></a><strong>.</strong></blockquote><p>Una vez incluída la dependencia, los <strong>ViewModels</strong> tendrán la posibilidad de recibir como parámetro un objecto SavedStateHandle que se encargará de guardar y de devolvernos información aún en aquellos casos donde nuestro proceso fue terminado por el sistema.</p><p>Podemos hacer uso del delegate de viewModels y nos quedaría de la siguiente manera:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d041261d70a7f6ddde9a2f0a5a159f80/href">https://medium.com/media/d041261d70a7f6ddde9a2f0a5a159f80/href</a></iframe><p>Nuestro ViewModel nos quedaría de la siguiente manera:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bb995cd6b168110c6b4ae02f03c746b/href">https://medium.com/media/7bb995cd6b168110c6b4ae02f03c746b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a86772120029f31c08a74a048f552b5b/href">https://medium.com/media/a86772120029f31c08a74a048f552b5b/href</a></iframe><p>Si prestamos atención a nuestro constructor, estamos recibiendo el objeto state de tipo <strong>SavedStateHandle.</strong> A través de este, podremos guardar y acceder luego a los datos que guardemos ahí. Si bien estamos guardando un objeto del tipo Serializable, podemos guardar <a href="https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate#acceptable-classes">otros tipos de datos</a>.</p><p>Una particularidad de este objeto, es que nos permite obtener un valor que hayamos guardado anteriormente a través de un <strong>LiveData</strong>. En el <em>snippet</em> anterior podemos ver como recuperamos la posición del <em>scroll</em> de un <strong>RecyclerView </strong>en caso de que nuestro proceso muera.</p><blockquote>Cada una de las vistas es capaz de guardar <strong>sus propios datos</strong> en caso de cambios de configuración, pueden comprobar que sus <em>recyclers </em>y cualquier otra vista mantiene su información. Básicamente cada view que contenga un id implementa su propio onSaveInstanceState.</blockquote><p>Dijimos que nuestro objeto sobrevive la finalización del proceso por parte de Android. Veamos cómo validarlo utilizando el proyecto que dejaré al final del artículo.</p><p>Una vez instalada la aplicación en nuestro dispositivo (o utilizando un emulador), vamos a recrear el proceso de destruír nuestro Activity, entonces al recrearse deberíamos quedar en el mismo estado:</p><ol><li>Abrimos la <em>app</em> de ejemplo</li><li>Scrolleamos <em>“un poco”</em></li><li>Mandamos la <em>app</em> a <em>background.</em></li><li>Buscamos la app utilizando el <strong>adb </strong>y la matamos.</li><li>Al volver a la app, chequeamos que efectivamente nuestra app quedó con el recycler en la posición en que lo dejamos.</li></ol><blockquote>Para buscar nuestra app en los procesos del dispositivo hacemos <strong>adb shell ps -A | grep com.my-package </strong>y para finalizar el proceso <strong>adb shell am kill com.my-package</strong></blockquote><p>Si tenemos habilitado en nuestros dispositivos las opciones de desarrollador, podemos configurar la opción <strong><em>Don&#39;t keep activities </em></strong>para emular matar el proceso en caso de cambiar de <em>Activity</em> o enviarla a <em>background</em>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5VKbvrjxpVJCM%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2F5VKbvrjxpVJCM&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2F5VKbvrjxpVJCM%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="348" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec7f12ff2e922662d7de480048f888aa/href">https://medium.com/media/ec7f12ff2e922662d7de480048f888aa/href</a></iframe><h4>Momento… mis ViewModels usan Interactors.</h4><p>Así se encuentren trabajando con alguna arquitectura en particular para toda su aplicación, como pueden ser <strong>Clean Architecture</strong> o <strong>IDD</strong>, o bien, estén haciendo <em>unit testing </em>sobre sus ViewModels, es necesario inyectarles otros objetos (dependencias), por lo que el uso del <em>delegate </em>tal cual lo usamos no nos sirve.</p><p>Lo que necesitamos es indicarle a nuestro <em>delegate </em>cuál es el <em>factory</em> con el que tiene que construír nuestro ViewModel y para poder hacer uso de <strong>SavedState</strong>,<strong> </strong>tenemos que extender del AbstractSavedStateViewModelFactory. De esta manera, podemos construír nuestro ViewModel con todas sus dependencias y adicionar el SavedStateHandler.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de7c63527588221727c64424e9b428f7/href">https://medium.com/media/de7c63527588221727c64424e9b428f7/href</a></iframe><p>De aquí podemos identificar algunos objetos que valen la pena mencionar, para entender cómo se logra el objetivo de preservar nuestros datos:</p><ul><li>SavedStateRegistryOwner: Básicamente lo que necesitamos es alguna clase que pueda manejar un SavedStateRegistry. En nuestro caso, le hemos provisto this porque Fragment implementa esta interfaz.</li><li>AbstractSavedStateViewModelFactory recibe un segundo parámetro que hemos puesto como null (opcional en realidad) nos permite en caso de no tener estado previo, proveer un Bundle con info por <em>default.</em></li></ul><h4>Casos prácticos</h4><p>Esta implementación que presentamos es un mero ejemplo y quizás, poco útil y hasta trivial. Los <em>recyclers</em>, al igual que todas las vistas a las que hayamos indicado un <em>id (</em>identificador) son capaces de guardar su propio estado. Sin embargo, <strong>SavedState</strong> puede ser una solución a la hora de evitar crashes en flujos complejos, que requieran transiciones entre varios fragments, como pueden ser flujos de login, compra, carga de encuestas, etc; en donde nuestra app puede ir a <em>background, </em>ser destruída por Android y al regresar, no contamos más con esa información necesaria que creíamos tener asegurada ocasionando <em>crashes </em>en producción, problemas de usabilidad y mala experiencia de usuario.</p><h3>Conclusión</h3><p>Los ViewModel han sido uno de los patrones de arquitectura de esos que han llegado para quedarse definitivamente (o por lo menos durante un tiempo). Han sabido combinar el patrón <strong>MVVM</strong> y el ciclo de vida de Android de tal manera que, <strong>bien utilizados</strong>, nos permiten obtener buenos resultados de manera segura. <strong>SavedState </strong>como complemento, es simplemente más útil aún para aquellas ocasiones y contextos en los que necesitamos ir más allá, unificando las responsabilidades y asegurandonos que no importa qué pase con nuestra aplicación en <em>background, </em>la información seguirá allí.<br>Adelante, pruébenlo!</p><p>Pueden encontrar todo el código utilizado en el siguiente repositorio:</p><p><a href="https://github.com/nogueirasjorge/saved-date-example">nogueirasjorge/saved-date-example</a></p><p>Para contactarnos, @<a href="http://twitter.com/nogueirasjn">nogueirasjn</a> en 🐦.<br>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9203ecc92b53" width="1" height="1" alt=""><hr><p><a href="https://medium.com/droid-latam/un-viewmodel-para-guardarlos-a-todos-9203ecc92b53">Un ViewModel para guardarlos a todos</a> was originally published in <a href="https://medium.com/droid-latam">Droid LATAM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your Android application rock SOLID — Dependencies]]></title>
            <link>https://proandroiddev.com/make-your-android-application-rock-solid-dependencies-ea0af48e5481?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea0af48e5481</guid>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Tue, 24 Mar 2020 20:08:30 GMT</pubDate>
            <atom:updated>2020-03-24T20:08:30.241Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make your Android application rock SOLID — Dependencies</h3><p>We&#39;ve arrived in the last chapter of this series of posts about SOLID in Android development. Let&#39;s find out the power of Dependency Inversion and how to use it in our daily work to create maintainable and robust apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKbNoO0zPruXOd7oNPcWmQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Markus Spiske</a> on <a href="https://unsplash.com/s/photos/border?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Recap</h3><p>We are finally here! Yay!!!</p><p>The last chapter of the SOLID series we started some weeks ago has come and guess what? We haven&#39;t talked about one of the most powerful and useful principles yet… The <strong>Dependency Inversion Principle (DIP)</strong>. The famous <strong>D </strong>of SOLID acronyms.</p><p>Before starting to talk about the principle, let&#39;s make a recap about what SOLID is and where to find more information about it.<br>If you are discovering the SOLID series I&#39;m writing from this post, you should consider reading the previous chapters which could be found in the links above, although it is not <em>mandatory.</em></p><ul><li><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-one-ba71774f864e">Make your Android application rock SOLID [Part One]</a></li><li><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-two-438022240480">Make your Android application rock SOLID — Open Close</a></li><li><a href="https://medium.com/@nogueiras/make-your-android-application-rock-solid-part-three-4397f3c866a2">Make your Android application rock SOLID [Part Three]</a></li><li><a href="https://proandroiddev.com/make-your-android-application-rock-solid-interfaces-84529a65f4a1">Make your Android application rock SOLID — Interfaces</a></li></ul><p>A full explanation of the SOLID principles could be found in the first section in the Single Responsibility Principle article.</p><h3>Dependency Inversion</h3><p>After reading and practicing with the Dependency Inversion Principle a lot, I cannot imagine myself not using it. Whether you are an experienced Android developer or not, you should learn this principle and put it in practice since the beginning of your work. Don&#39;t worry, you can start using it in an advanced application, one step at the time and once you get used to it, it will come to you like that song you hear on the radio and can&#39;t stop singing. But before starting to talk about <strong>inversion</strong><em>, </em>let&#39;s focus on what a <strong>dependency</strong> is.</p><h4>Dependencies</h4><p>At least once in life, a dependency graph has appeared on your computer, just in front of you (If don&#39;t, you should consider <a href="https://developer.android.com/studio/build/dependencies.html#view-dependency-tree">analyzing your app</a> to understand them). That graph is like a photo of how your <strong>classes, libraries, </strong>and<strong> modules </strong>cooperate together at a given time to achieve your application&#39;s goals.</p><p>So, a <strong>dependency</strong> is something we <em>depend on</em>. It is something we need to complete a task, do some math, send an email, read a file, and so on. It&#39;s important to you not just identify your dependencies but understand them. That will force you to create flexible and maintainable apps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71064fb8f7f76b3e00df3488c6d4daf9/href">https://medium.com/media/71064fb8f7f76b3e00df3488c6d4daf9/href</a></iframe><p>The example above represents a dependency in our Calculator class. To display the result on the screen, our Calculator needs to call the ScreenDisplay class. The calculator <em>knows </em>the kind of display we are working on.</p><p>We can add some extra functionality to our <strong>Calculator</strong> by saving the last <strong><em>x </em></strong>values we got. Let&#39;s make it happen! 💪</p><p>The first version of our new feature needs to keep the last values obtained from the calculator just for the current session. In that case, saving into memory would be enough.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef3256f363d6c753f0bcffde67d99b1f/href">https://medium.com/media/ef3256f363d6c753f0bcffde67d99b1f/href</a></iframe><p>Now, Calculator <em>depends on </em>CalculatorRepository. This means, we also <em>know</em> <em>exactly</em> which instance and which type of repository we are implementing.</p><blockquote><strong>Note: </strong>Dependencies are not bad, we just need to manage them carefully.</blockquote><p>After a few days, we start to think that maybe it&#39;s better if we store these values in another place; somewhere allowing the user to check the previous calculations later, even if they close the application.</p><p>We are Android Engineers, right? So, let&#39;s use some Android stuff to solve our problems… Mmm, what about <strong>SharedPreferences</strong>?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7935f270a40c5e843ba3228370b3e51b/href">https://medium.com/media/7935f270a40c5e843ba3228370b3e51b/href</a></iframe><p>Well… pretty easy right? But we needed to <em>change </em>the Calculator itself to store a result. This change has nothing to do with the logic of making a calculation. Our packages imports changed (because it&#39;s a different repository class), our method signature doesn&#39;t (but it could) and we forget the CalculatorRepository to take acknowledge of the new SharedRespository. 🤔 <strong><em>Can you see the problem here?</em></strong></p><p>Let&#39;s think about the possibility of our <strong>Calculator </strong>becomes famous in the <em>PlayStore </em>and we decided to change again the Repository, this time for a <a href="https://developer.android.com/topic/libraries/architecture/room">Room</a> repository. In that case, the setup, the configuration and the classes involved will be more than just <strong>&quot;another class&quot;. </strong>We have a big problem here, a <em>coupling</em> problem.</p><blockquote>Coupling could be good, always you know what to be coupled and what not.</blockquote><p>We need to find a way to stop be coupled to a dependency that could be changed in the feature. We need to find a way to avoid <em>changing </em>code that should not be changed when these implementations change.</p><h4>Interfaces to Decoupling</h4><p>We learned in the previous article that interfaces have several good uses. One of them is to <em>decouple</em>. What do you think if I tell you that repositories can be changed and Calculator won&#39;t even notice about it?</p><p>The first thing to do to achieve this is to create an interface for the Calculator communication. Let&#39;s call it CalculatorRepository:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eccce233a41afc7a1c037736424194a9/href">https://medium.com/media/eccce233a41afc7a1c037736424194a9/href</a></iframe><p>And we also change our Calculator class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a94d670c3d91eddfc9fc600034e89e4/href">https://medium.com/media/7a94d670c3d91eddfc9fc600034e89e4/href</a></iframe><p>What we did is <strong><em>injecting </em></strong>the CalculatorRepository <strong>interface </strong>and passing to the Calculator an instance of the SharedRepository class. <em>This is called dependency injection, it&#39;s another powerful practice we won&#39;t cover in deep in this article.</em><br>The Calculator does not know which type of persistence tool is saving the data we want to save. With this approach, we <strong>stop depending on any specific Repository. </strong>This avoids the necessity of being changing the Calculator class when we decide to change the persistence tool, with the possible addition of new bugs; And we did it with just an <strong><em>interface</em></strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_tQiYkFFtVC3pK7XhQWKCQ.png" /><figcaption>Calculator App architecture</figcaption></figure><p>We can say so, that the <strong>core</strong> <strong>domain layer </strong>of our <strong>Calculator Application</strong> holds the Calculator class and the CalculatorRepository because these are the classes where we define the business rules, the entities, and all the collaborator classes to achieve the application purpose. We <strong><em>should</em></strong> <strong><em>not</em></strong> change the business rules because of the <strong>persistence</strong> <strong>tool</strong>… Or any other tool, library, module, etc.</p><p>In other words, this means that the Calculator class <strong><em>depends on </em></strong>its own domain (inside the <strong><em>core</em></strong> package), the CalculatorRepository, and the <strong>persistence tool </strong>(i.e. the SharedRepository, out of the <em>domain</em>) <strong><em>depends on</em></strong> the CalculatorRepository, which is into the <strong>domain</strong> layer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bbf30491df75f223ee5f0794ac4a2ff/href">https://medium.com/media/1bbf30491df75f223ee5f0794ac4a2ff/href</a></iframe><p>We have successfully <strong>Inverted</strong> our <strong>Dependencies</strong>. Remember, we decide what to depend on and whatnot.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FRrVzUOXldFe8M%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FRrVzUOXldFe8M%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FRrVzUOXldFe8M%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5ee627c67ff4ec3e4e0d897500ee961/href">https://medium.com/media/c5ee627c67ff4ec3e4e0d897500ee961/href</a></iframe><h4><strong>Decoupling from <em>modules</em> and libraries</strong></h4><p>The same approach we used when decoupling our <strong><em>core domain</em></strong> from the <strong>infrastructure </strong>is useful to decouple from internal modules and libraries.<br>If your application has more than one module, it&#39;s desirable that every module has its own domain, which means we should changeless as possible in a module if another module needs to change. Whatsmore, if you had to replace a module for another (i.e. you have an adapter module for a given library or a completely different feature version you need to change) you won&#39;t have to modify the core in the module which <em>&quot;depends&quot;</em> on it. &quot;Depends&quot; is relative because of the DIP. The module that <em>depends </em>on the module that changes, does not depend directly on the module but to its own <em>domain interface.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b401fc919b17f1a96e7f6325ae05ab0/href">https://medium.com/media/9b401fc919b17f1a96e7f6325ae05ab0/href</a></iframe><p>This approach also applies to external/internal libraries.</p><h3><strong>Android Styling</strong></h3><p>These principles are present in a big part of the world application solutions (unfortunately, in another big part of them don&#39;t). We will explore the Android Styling system to understand how this particular principle can help us to make our application styling extensible and easy to change.</p><p>You <em>know</em> what <strong>theme </strong>is in Android right? But… do you know how does it work? How is it possible to change the way our application looks just by changing the theme?</p><p>Let&#39;s make it a little bit clear with an example: Imagine that you define the calculator primary color using the colorPrimary theme attribute and the application has to modes, the free one with a basic calculator and the premium one, where the user pays a monthly subscription and the calculator turns into a scientific (with a beautiful change of color with it of course).</p><p>As you are using <strong>Themes</strong>, you will have at least two; one for the free app&#39;s users and another for the users with a subscription. So, if the background color of the <strong><em>equals button</em></strong> must change along with the user subscription you need to set something like this in the widget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79840ec16dc47e23f1adc32eef15dfa9/href">https://medium.com/media/79840ec16dc47e23f1adc32eef15dfa9/href</a></iframe><p>And in your <em>styles </em>file<em>, </em>you define your themes like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5456a34f77df8cd52c3e7516322fee4a/href">https://medium.com/media/5456a34f77df8cd52c3e7516322fee4a/href</a></iframe><p>Once subscribed, just restart the CalculatorActivity and apply the new Theme.Calculator.Subscription to change the background color of your <strong><em>equals button </em></strong>to the premium one.</p><p>If you haven&#39;t noticed it already, this is the same as having an interface called Theme with a colorPrimary method implemented by both the <strong>Free</strong> and the <strong>Subscription</strong> theme. Our application is not depending directly on a color resource to define the <strong><em>equals button</em></strong>&#39;s backgroundColor. We <em>depend </em>on an <em>&quot;interface&quot;, </em>we have inverted the dependency once again.</p><p>If you wanna learn from styling and themes, I highly recommend this series of posts from <a href="https://medium.com/u/22c02a30ae04">Nick Butcher</a> and<strong> </strong><a href="https://medium.com/u/9303277cb6db">Chris Banes</a><strong> </strong>which starts from <a href="https://medium.com/androiddevelopers/android-styling-themes-vs-styles-ebe05f917578"><em>here</em></a><em>.</em></p><h3><strong>Conclusion</strong></h3><p>After several weeks (and posts) we arrived at the last chapter of this SOLID series to learn about the <strong>Dependency Inversion Principle</strong>. It&#39;s all over the well-coded apps and it&#39;s useful in several ways. We have covered how you can use it to decouple your modules and to decouple your app from external libraries.</p><p>This kind of practice will lead you to become a better Android engineer. It&#39;s fine to follow the last implementation of some Android library, or migrating to <a href="https://developer.android.com/jetpack/androidx">AndroidX</a>, using the <a href="https://developer.android.com/topic/libraries/architecture">Architecture Components </a>(which you should obviously try) and other Android particular practices, but what you need to learn and be focus to are good programming practices, as SOLID, Design Patterns and Principles, etc. There are lots, hundreds of posts and books about these topics but they are not always connected to real code, real problems. This series intended to connect those practices with Android programming and I really hope you can find it useful and can make a change in the way you think your <br>solutions.</p><p>Stay connected 😄<br>Happy Coding! ✍️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea0af48e5481" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/make-your-android-application-rock-solid-dependencies-ea0af48e5481">Make your Android application rock SOLID — Dependencies</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your Android application rock SOLID — Interfaces]]></title>
            <link>https://proandroiddev.com/make-your-android-application-rock-solid-interfaces-84529a65f4a1?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/84529a65f4a1</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Fri, 06 Mar 2020 08:22:34 GMT</pubDate>
            <atom:updated>2020-08-23T23:47:03.866Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make your Android application rock SOLID — Interfaces</h3><p>It&#39;s time to talk about Interfaces. They can be very useful or can cause us a lot of problems. Just remember, <em>not all the birds can fly</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJ3vsLjLB2LQ6SkTH7VVqA.png" /><figcaption>Credit: <a href="https://www.vippng.com/maxp/hiRJi/">https://www.vippng.com/maxp/hiRJi/</a></figcaption></figure><h3>Recap</h3><p>Before starting to put some lights over the fourth principle (The Interface Segregation Principle), let’s make the &quot;recap&quot; of the previous ones.</p><p><strong>SOLID</strong> is the acronym that intends to join several principles about good design practices in software development. We have covered the first three letters of it and today it is the time for ISP. If you haven&#39;t read the previous articles, you can find them below:</p><p><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-one-ba71774f864e"><strong>S</strong>ingle Responsibility Principle</a><br><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-two-438022240480"><strong>O</strong>pen-Closed Principle<br></a><a href="https://medium.com/@nogueiras/make-your-android-application-rock-solid-part-three-4397f3c866a2"><strong>L</strong>iskov Substitution Principle</a><br><strong>I</strong>nterface Segregation Principle<br><strong>D</strong>ependency Inversion Principle</p><p>A full explanation of SOLID principles could be found in the first section in the SRP article.</p><h3>What does &quot;Interface Segregation&quot; mean?</h3><p>Think about <em>interfaces</em> and why we use them. We tend to use them in order to define protocols, communication, decoupling (we&#39;ll talk more about it in the last chapter of this series) and why not? To define behavior.</p><h4>Behavior</h4><p>We use classes and subclasses to define inheritance. But sometimes, we use interfaces to define behavior over those classes.</p><blockquote>Just remember… not all the birds can fly.</blockquote><p>Let&#39;s add some code to clarify this. We are building an Android game for a Zoo (I&#39;m using it as an example, this has nothing do with the debate of having animals out of its natural habitat) and you have a Bird category you need to represent as one of the possible characters in the game. If the user selects a bird, it can have some special skills, different from the users who select felines, easy peasy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bafd34090f4a2e13fe498501af889fb/href">https://medium.com/media/1bafd34090f4a2e13fe498501af889fb/href</a></iframe><p>One of the first <em>brave </em>testers of the application selects a <em>chicken</em> as his first character. After playing some time, he says to the <em>stakeholders:<br>- </em>The game is funny, it&#39;s easy to play but… I can fly with my chicken… and chickens <strong><em>don&#39;t fly</em></strong> at all.</p><p><em>What do you think has happened here?</em> The main problem is that the developers used interfaces to define categorization instead of using them to define behavior.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdfe037c07c629c7a428e0eb8a5498fa/href">https://medium.com/media/cdfe037c07c629c7a428e0eb8a5498fa/href</a></iframe><p>Don&#39;t worry, said the developers. We can fix this problem quickly producing the following change:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cda98abfef9df5c78cb07f0be700df03/href">https://medium.com/media/cda98abfef9df5c78cb07f0be700df03/href</a></iframe><p>After building and running the game, the tests passed as expected. If you select the chicken, it does not fly.</p><h4>Code Smells</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*m9B5ZedOE9lgkRWCyXNjKA.jpeg" /><figcaption><a href="https://www.aircon-servicing.com.sg/articles/how-to-get-rid-of-bad-smell-from-aircon.html">Credits</a></figcaption></figure><p>We call a &quot;code smell&quot; to those things in the code that does not leave us to sleep well at night. A code smell is something you are pretty sure it&#39;s a possible problem in the future, it&#39;s something you doubt of leaving it <em>that</em> way, or maybe it&#39;s something you don&#39;t know it&#39;s well coded, but you couldn&#39;t find the<em> &quot;right way&quot;</em> to do it.</p><p>Leaving a method from a protocol (interface) without implementation is a code smell.</p><p>Particularly, in this case, we have to leave the fly method in the Chickenclass without its implementation because of the <em>&quot;Naturaleza&quot;</em>. <em>Chickens can&#39;t fly.</em></p><p>We said that the main problem was having used the interface to categorize something instead of defining some behavior. What if we leave the categorization of Bird as an <strong>abstract</strong> class (with some eat method or the number of wings — I&#39;m not sure if all birds have wings but I&#39;ll suppose they all do) and we create an <strong>interface</strong> to add the ability to fly (which not all birds have). In this case, the <strong>interface</strong> could be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e7dc5a9b5838942fa35c3b3bcd374c1/href">https://medium.com/media/2e7dc5a9b5838942fa35c3b3bcd374c1/href</a></iframe><p>The flyable <strong>interface</strong> just defines a behavior. An ability. The ability of flying, which of course will not be implemented in the Chicken class. Removing the fly method from the Bird interface (before converting it into an <strong>abstract</strong> class) is segregation.</p><h4>Does my interface need to be &quot;segregated&quot;?</h4><p>Well, it depends on how is your interface defined and its purpose. Let&#39;s think and Android example… this is why we are here after all, isn&#39;t it?</p><p>We are creating an Android application for a streaming company that needs to offer its users the best experience in movie searching, in order to retain the users and they do not migrate to another streaming app. This app has a particular business rule, you pay for the movies you want to watch at that&#39;s all.</p><p>Imagine we have an Activity with some king of GridView (which can be implemented with a RecyclerView + GridLayoutManager and won&#39;t be covered by this article). The first thing the company asks us is that they desire to display a preview of the movie is the user clicks on the movie cover. So we create a listener this way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14a539f38f8b122514dd324ec5471250/href">https://medium.com/media/14a539f38f8b122514dd324ec5471250/href</a></iframe><p>Perfect! Then we need to also display a dialog to confirm the purchase of the movie when the user clicks on the purchase icon into the movie slot. And they also need to show <em>more or less</em> similar movies is the user indicates so by clicking in another section of the slot. So, we update our <strong>interface</strong> and results to be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13fb70c9bd171bdf824c856272e3a484/href">https://medium.com/media/13fb70c9bd171bdf824c856272e3a484/href</a></iframe><p>In this case, this full interface achieves the movie slot goals as a listener. Anything needs to be &quot;separated&quot;. Anything needs to be &quot;segregated&quot;. But… What would happen is this interface becomes a…</p><h4>One listener to rule them all?</h4><p>We are very confident about the design of the MovieGridActivity and we are also ready to start a new section of the App. As a streaming Android app, the next section would be about… <em>movies</em>, of course!</p><p>The owners of the company ask us to add another section where the user can &quot;suggest&quot; to the platform (the company itself) to add some movies to the catalog so he or she can purchase them.<br>We&#39;ll have another <strong>Grid</strong> with some movies we can click and request to be added for future purchases. So we take our great MovieListener and implement:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93f3275e92daf656876fd6cf05987cdb/href">https://medium.com/media/93f3275e92daf656876fd6cf05987cdb/href</a></iframe><p>We are running into a problem here. The <strong>interface</strong> we are using has a lot of methods that are not needed in this <em>context. </em>Leaving a comment to mention this method should not be implemented is a <em>code smell</em>. What if we accidentally implement one of those methods… Well, we could… Could we? <em>Shall we</em>? Who really knows. The method can be called and someone could implement the listener into the ViewHolder and transform this innocent empty method in a mess.</p><p>To reduce the possibility of making a mistake (or worse, make <em>others </em>commit a mistake) we should &quot;split&quot; the interface in at least two, one for the case of covers click and the other for the purchase section resulting in:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20616eed9d32ea6eba9977e7448eda3d/href">https://medium.com/media/20616eed9d32ea6eba9977e7448eda3d/href</a></iframe><p>… which is a better approach because it does not force us to leave confusing unimplemented methods if we don&#39;t really need them.</p><h3>Conclusion</h3><p>We have learned that not all the birds can fly, and also that you have to keep your interfaces focused on the problem they are solving and in anything else. Reuse them may feel cheap but in the end, it could be painfully cause&#39; it will make your code hard to read, understand and of course, maintain.</p><p>The final chapter is coming very soon. The last episode will be very interesting because the topic is one of the most useful when you work in an Android multi-module environment. How to avoid a change in a module impacts directly in another one? How do you prevent yourself from changing a lot of classes if you need to update a library or a module? We&#39;ll be exploring the Dependency Inversion Principle to help us improve our code flexibility.</p><p>Follow me on Twitter at @nogueirasjn and, as I always say, if you found this post useful or interesting to you, please support with a clap 👏 and a share with your friends and colleges.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84529a65f4a1" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/make-your-android-application-rock-solid-interfaces-84529a65f4a1">Make your Android application rock SOLID — Interfaces</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your Android application rock SOLID — Liskov Substitution]]></title>
            <link>https://nogueiras.medium.com/make-your-android-application-rock-solid-part-three-4397f3c866a2?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/4397f3c866a2</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[liskov]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Fri, 28 Feb 2020 03:29:53 GMT</pubDate>
            <atom:updated>2020-08-21T21:28:57.481Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make your Android application rock SOLID — Liskov Substitution</h3><p>Let’s dig a little bit into the Liskov Substitution Principle and how this can be very harmful to your project when you do not take it seriously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BacXmIeU6xcQe2qrhrbiVg.jpeg" /><figcaption>CREDIT: CHRIS BRUNSKILL/FANTASISTA/GETTY IMAGES</figcaption></figure><h3>Recap</h3><p>Before starting to put some lights over the LSP, let’s make a little recap about what is it all about.</p><p>The Liskov Substitution Principle is part of the SOLID principles — the L to be precise — , which means:</p><p><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-one-ba71774f864e"><strong>S</strong>ingle Responsibility Principle</a><br><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-two-438022240480"><strong>O</strong>pen-Closed Principle<br></a><strong>L</strong>iskov Substitution Principle<br><a href="https://proandroiddev.com/make-your-android-application-rock-solid-interfaces-84529a65f4a1"><strong>I</strong>nterface Segregation Principle</a><br><strong>D</strong>ependency Inversion Principle</p><p>A full explanation of the SOLID principles could be found in the first section in the SRP article.</p><h3>Theory</h3><p>Yeah, I know. You already hear about this principle a lot of times before today, and what it means. Probably you ask some people for an explanation and you got several answers, or maybe, instead of an answer… a meaning.</p><blockquote>“The Liskov Substitution Principle is about inheritance”</blockquote><p>Well… yeah, something about inheritance is… but it is not just about it. Let&#39;s try with another one:</p><blockquote>“The Liskov Substitution Principle tells you that you need to be able to exchange objects from the same ‘family’ “</blockquote><p>Well… this is also true, but it is not complete yet.</p><p>Remembering what we said in the first chapter of this series, in the introduction section — which I recommend to read if you hadn&#39;t yet — is</p><blockquote>&quot; if we are building a system with interchangeable parts, those parts must agree to a contract that allows them to be substituted for another.&quot;</blockquote><p>Well, this last definition likes me a little bit more than previous ones. Basically, what it says is that if there is a contract (an interface, an abstract class with template methods) and you also have several objects which must agree to that contract, wherever you use one of that objects, the expected behavior must be… expected.</p><p>What about an example to clarify this? Let&#39;s do it.</p><h3>Java&#39;s List Interface and Collections&#39; sort</h3><p>One of the most annoying cases of Liskov Substitution fractures is the sort operation into the Collections class, which of course I&#39;ve found by receiving an unexpected (?) error in an application I was building.</p><p>In order to sort a collection in Java, you can use the sort helper method in the <strong>Collections</strong> class which takes an instance of a <strong>List&lt;T&gt;</strong> and a <strong>Comparator</strong> instance ( Kotlin makes this easiest with its <a href="https://bezkoder.com/kotlin-sort-list-objects/"><em>sortBy</em></a><em>() </em>) :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81876ee2272d9b22aaa8f8774992b405/href">https://medium.com/media/81876ee2272d9b22aaa8f8774992b405/href</a></iframe><p>This means you can pass any object that implements the <strong>List&lt;T&gt;</strong> interface, where <strong>T</strong> is the concrete <strong>Type</strong> of the objects into the list. Imagine you have in your Android application a custom <strong>Array</strong> and you need to convert it to a <strong>List, </strong>you probably will do something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e39fd68356c5cc1cddf2e16510ba2844/href">https://medium.com/media/e39fd68356c5cc1cddf2e16510ba2844/href</a></iframe><p>Everything fine! You create your list of Strings, try to sort them and <strong><em>Baam! Crash!</em></strong></p><blockquote>UnsupportedOperationException was thrown</blockquote><p>At first, you probably won&#39;t see the problem here. It should not be any. But, digging a little bit in the documentation of both, <strong><em>Arrays.asList()</em></strong><em> </em>and <strong><em>Collections.sort(), </em></strong>you could find that <strong>sort</strong> operation can throw this exception if the <strong>List&lt;T&gt;</strong> provided <strong>does not support the add operation </strong>and <strong>Arrays.asList()</strong> returns a <a href="https://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#asList%28T...%29">&quot;<strong>fixed-size</strong> list backed by the specified array&quot;</a>.</p><p>The returned list by the <em>asList()</em> method violates the Liskov Substitution Principle due to the <strong>List&lt;T&gt;</strong> is not replaceable in the context of the sort operation. <br><strong><em>Collections.sort(…)</em></strong> expect <strong>ANY</strong> instance of a <strong>List&lt;T&gt;</strong> and we provided an instance of it which does not fully support the <strong>List&lt;T&gt;</strong>&#39;s protocol. Of course, it implements the protocol but the add operation is canceled with an exception thrown in the method call.</p><h3>Conclusion</h3><p>The case we saw it&#39;s just one of the many examples we can find around the java code, and probably in many other languages. In this case, we &quot;have nothing to do with it&quot; because it&#39;s not on own responsibility. However, it&#39;s important to avoid this kind of class hierarchy constructions in our applications in order to avoid unexpected behavior in runtime and poor design.</p><p>Note that, despite the LSP talks about hierarchy, the example above is not about hierarchy but protocols instead. The important thing is, whether you are using an Interface or an abstract class, you are defining a contract and that contract must be agreed by the current classes which implement it or by the future ones.</p><p>Stay tuned for the next post of this series (The Interface Segregation Principle), and sorry for the delay in the current one.</p><p>In the meantime, you can follow me on Twitter at @nogueirasjn and, as I always say, if you found this post useful or interesting to you, please support with a clap 👏 and sharing it.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4397f3c866a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your Android application rock SOLID — Open Close]]></title>
            <link>https://proandroiddev.com/make-your-android-application-rock-solid-part-two-438022240480?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/438022240480</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 11:12:03 GMT</pubDate>
            <atom:updated>2020-03-24T17:30:14.325Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make your Android application rock SOLID — Open Close</h3><p><strong>Open</strong> your mind and <strong>Close</strong> all your prejudgements. Let’s discover and discuss the Open-Close Principle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-JIUxUzo4Hu4lLSUPawvBQ.jpeg" /><figcaption>photo by <a href="https://pixabay.com/users/qimono-1962238/">qimono</a>.</figcaption></figure><h3>Recap</h3><p>We have already made an introduction about the SOLID principles in my previous article and we have described the first of them, the Single Responsibility Principle. It’s time to talk about the next of them, the Open-Close Principle. But before starting to talk about this principle let’s make a recap of all the principles:</p><p><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-one-ba71774f864e"><strong>S</strong>ingle Responsibility Principle</a><br><strong>O</strong>pen-Closed Principle<br><a href="https://medium.com/@nogueiras/make-your-android-application-rock-solid-part-three-4397f3c866a2"><strong>L</strong>iskov Substitution Principle</a><br><a href="https://proandroiddev.com/make-your-android-application-rock-solid-interfaces-84529a65f4a1"><strong>I</strong>nterface Segregation Principle</a><br><strong>D</strong>ependency Inversion Principle</p><p>In the first section (the SRP article), you will find a complete explanation of the SOLID Principles.</p><h3>The Open-Close Principle</h3><p>As we did before, in the previous chapter of this SOLID series, it’s convenient to start by a definition of the principle.</p><blockquote>The Open Close Principle says that “a piece of code must be opened for extension and closed for modification”</blockquote><p>In other words, you need to define your artifacts in a way you do not need to change them to add new functionality; to extend functionality. This may sound easy to achieve, and it is. But, a lot of artifacts had been built violating this principle. Some of them you may have written in the past and belong to your <strong>legacy </strong>code and others no so <strong>legacy</strong>. Let’s focus on the <em>no-so-legacy</em> code, which means a great opportunity to start working on your design.</p><p>Like in the Single Responsibility Principle, you can apply this principle at several levels. A “piece of code”, formerly called “artifact”, can be a class or an entire module. <em>Can’t you imagine what is all this about yet?</em></p><h4>Module</h4><p>We are going to assume that we are working on an Android application that is separated into different modules (yes, we have learned and abandoned completely the monolithic apps, right?). We have also learned that every module should do one single thing. Let’s pay special attention to the <strong><em>notification</em></strong> module.</p><p>The <strong><em>notification</em></strong> module is dedicated to sending notifications to other modules from different parts of the app. At the time we analyze this application, everything is working fine and seems to not be any problem at all. However, the issues come when we need to send a notification to a new module.</p><p>Digging a little bit into the module, we can find the<strong>NotificationSender</strong> class with this structure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfd64f8c69c3675a317d9a33c01aa58f/href">https://medium.com/media/bfd64f8c69c3675a317d9a33c01aa58f/href</a></iframe><p>If our team is the one who has to make the change, they will have to come here and add another case in the <em>send</em> method. The team is almost sure about the place it needs to change and they can do it in a couple of hours. But, is this structure respecting the Open Close Principle? Well… it&#39;s not.</p><p>— Why do you say to us this is wrong? Isn&#39;t it the right place to change the code?<br> — Yes, it is. But it&#39;s also violating a principle.<br> — But, but… the entire module has been refactored and now it is respecting the Single Responsibility Principle. I read from you!<br> — It&#39;s not respecting the Open Close Principle.<br> — But why??</p><p>Well, the artifact we built is not closed for modification. To complete the task, the team needed to add some code in there, not only modifying the <strong>NotificationSender</strong> class but also making this module knows all other modules. A better approach will be, of course, that this module will be capable to send notifications to destinations without knowing them.</p><p>This can be achieved by letting this module to receive an uncertain number of <em>notifiable</em> objects, without really knowing which modules are really notifying. Whatsmore, this approach also allows them to remove <em>notifiable destinations </em>without even notice.</p><p>We will discuss how to achieve this in the next section when we talk about the OCP at the class level.</p><h4>Classes</h4><p>Classes are, the common and easiest place to find these problems. In the previous section, we talked about OCP at a module level. But, to remove this problem we need to solve the class level violation of the principle. Let&#39;s see how it works:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29598f954c5e50fcb2ef50bd1930be12/href">https://medium.com/media/29598f954c5e50fcb2ef50bd1930be12/href</a></iframe><p>The <strong>NotificationSender</strong> class only knows that is capable of notifying some <em>notifiable </em>objects ( which in our contract means <em>notifiable</em> modules ). It does not really know about which module is loaded to receive notifications and which isn&#39;t.</p><p>What should we do if we need to add another module no be notified? Yeah! You have guessed! NOT here!</p><p>It is just necessary to add another class in the <em>notifiable</em> list when creates the <strong>NotificationSender. </strong>If you need this class to be more flexible, you can change the status of the list by allowing other modules to add or remove modules to be notified.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fee8bba3d0e9362167408644903c317/href">https://medium.com/media/6fee8bba3d0e9362167408644903c317/href</a></iframe><h3>What about an Android example?</h3><p>Ok, I know, I know. I did not forget it. Let&#39;s make it happen.</p><p>Imagine you have a custom view in some <em>XML </em>file that needs to draw some objects depending on how many of them are received. The number of items you will have to draw, and of course, the items itself are coming as API response. The client (our Android app) will only be responsible for drawing them in the order we define, and of course, it will accept the number of items that it can draw and nothing else.</p><p>Assuming our items container is a <strong>ConstraintLayout </strong>and that we need to constraint the elements depending on how many of them came, our <em>Custom View </em>could be something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53d9e32c54d965d2165b47b01987476e/href">https://medium.com/media/53d9e32c54d965d2165b47b01987476e/href</a></iframe><p>The initializeWithItems function is unable to be extended because you need to modify the method, adding another when case to accept more items. We need to change this implementation in order to make the functionality extendable and to make this method closed for modification.</p><p>The first thing to do is extract an interface to tell our class we are going to add several objects to place items in a custom view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a30f82adbb5bf1737171349f2db244d/href">https://medium.com/media/2a30f82adbb5bf1737171349f2db244d/href</a></iframe><p>This is a simplified interface. You probably are gonna need to pass a copy of the ConstraintSet from the parent to place the items.</p><p>After that, by injecting to the Custom View a list of different ItemOrder objects, and changing the code in the addItems function, we can make our class <strong>open</strong> for extension and <strong>close</strong> to modification.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00481b81fd5311d015f94f5a9e4baa9c/href">https://medium.com/media/00481b81fd5311d015f94f5a9e4baa9c/href</a></iframe><h3>Conclusion</h3><p>We have learned the benefits of using the Open Close Principle paying special attention to its application at different levels. Every artifact that you build must be thought to aim not one single objective only but to be able to extend it’s functionality easily.</p><p>Violating the Open Close Principle it&#39;s a very common scenario in real-life so, no matter if you have found this problem in someone else code or you are about to create the problem, think about your buddy before letting it the way it is.</p><p>In the next episode of this series about SOLID we will discuss about the Liskov Substitution Principle, the <em>hardest</em> one.</p><p>Meanwhile, you can follow me on Twitter at @nogueirasjn and, as I always say, if you found this post useful or interesting to you, please support with a clap 👏.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=438022240480" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-two-438022240480">Make your Android application rock SOLID — Open Close</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your Android application rock SOLID — Single Responsibility]]></title>
            <link>https://proandroiddev.com/make-your-android-application-rock-solid-part-one-ba71774f864e?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba71774f864e</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Wed, 28 Aug 2019 12:20:42 GMT</pubDate>
            <atom:updated>2020-03-24T14:14:08.390Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make your Android application rock SOLID — Single Responsibility</h3><p>Discover, discuss and put in practice the SOLID principles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8oTVFbGfvOGrIcHNgSGAw.png" /><figcaption>Make your Android Application rock SOLID.</figcaption></figure><p>Have you ever found yourself navigating through the code you were working on for several days, trying to fix some sneaky bug you couldn’t find? Have you ever felt disappointed with the amount of time you spent when adding some new features to your code?</p><p>If this is a common scenario for you, it might be time to review your design.<br>But hey, don’t panic! Your Android app is not completely dead. There’s something you can still do about it. Let’s discuss how.</p><p>As an Android engineer, software quality has been one of my biggest priorities. Architectural patterns, good practices, and testing are all relevant (among other topics) in order to achieve robust Android applications. There are lots of papers, videos, and documents about this topic that you can easily find surfing the web, some of them really good ones.</p><p>But although there is a lot of information around the web, what is harder to find are examples of these, good ones… if you know what I mean.</p><h4>What is all this about?</h4><p>This series of posts is all about <strong>SOLID</strong> principles, didn’t I tell you already?</p><blockquote>“The SOLID principles tell us how to arrange our functions and data structures into classes, and how those classes should be interconnected”; Robert Martin, aka Uncle Bob.</blockquote><p>As I mentioned before, I am always pursuing high-quality code by creating the best solutions possible and good examples to validate that these practices actually work.</p><p>I have seen different kinds of apps all over my career, some of them very fragile ( we’ll discuss this concept later ), rigid, unable to tolerate changes and I can assure you that good design and code quality are at the end, the best option against the excuse of “not having time to make it right”.</p><p>This is the first of several posts I intend to write in which I will present to you some of the concepts you may already know about SOLID or even apply in your daily work without even noticing. We are going to name them, identifying them in the Android code and discuss how these patterns and practices can improve not only our code quality but ourselves as engineers.</p><h3>What does SOLID mean?</h3><p>SOLID is basically all the best practices and principles presented and practiced over the years which deliver good-quality apps put together.</p><p>In resume, the <strong>SOLID</strong> is the acronym of:</p><h4>Single Responsibility Principle</h4><p>This principle tells us that no matter if you are dealing with a block of code, a class or even an entire module, it should have one and only one reason to change.</p><h4><strong>Open-Closed Principle</strong></h4><p>This principle is more related to code design. It basically says that for a given system, in order to change its behavior you should add new code instead of changing existing code. It must be <strong>Open</strong> for extension and <strong>Closed </strong>for modification.</p><h4><strong>Liskov Substitution Principle</strong></h4><p>Maybe this is the most complicated principle to understand. However, we will discuss it deeply in future posts. In short, this principle says that if we are building a system with interchangeable parts, those parts must agree to a contract that allows them to be substituted for another.</p><h4><strong>Interface Segregation Principle</strong></h4><p>I believe this is one of the most violated principles by the Android framework and for Android developers. This principle prevents developers to depend on things they do not really need.</p><h4><strong>Dependency Inversion Principle</strong></h4><p>This is the most valuable principle in order to decouple your Android app from code you may change in the future due to strategical decisions. We’ll be clarifying this in future posts but, strictly speaking, the principle says that the code which implements high-level policies must not depend on code that implements low-level policies.</p><p>Take a deep breath… Take another one… Read the principles again… Ok, they are probably making more sense now… Great! You are prepared to start now. Let’s rock!</p><h3>SRP: Single Responsibility Principle</h3><p>Single Responsibility Principle, as known as the <strong>S </strong>in SOLID, seems to be the easiest to understand among the other principles. But, instead of being that, it is the most violated.</p><p>When you read the definition you may think… “this thing should DO one and only one thing only” and then try to act in consequence. However, <strong>the SRP tells us that given a piece of code it should have one and only one <em>reason </em>to change</strong>.</p><p>You may be thinking what a “piece of code” exactly means in an Android application and there is not a single answer for that. SRP is applied to several levels:</p><h4>Modules</h4><p>I imagine you are still here because you are an Android developer and something in you (or in your project) kept you reading this article. I invite you to take a look at your app design, precisely your modules and to compare them with the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*PnyzLd9JWv0y8LRX5pI9_w.png" /><figcaption>SRP violated at a module level.</figcaption></figure><p>This is a snapshot of an Android application with some modules. Let’s say that this app is about generating billings for a given company. A user can generate a bill, send it to the client, generate reports for the company and also generate reports to send to our clients with all the bills we made to them in a given period of time.</p><p>Whether you are satisfied or not with the number of modules, let’s assume this is the application design. Reviewing the modules in the app, we can see that there is a <strong><em>rest </em></strong>module which intends to handle all the things related to API communication. Why would you change something in this module? Probably if something related to the communication itself needs to be changed. You should avoid including other stuff in this module not related to the rest communication. Finally, the rest module has <strong>one and only one </strong>reason to change.</p><p>On the other hand, the <strong>common</strong> module seems to contain stuff related to all the other modules. This means that it has many reasons to change and violates the Single Responsibility Principle.</p><p>The company which this application belongs to has a new request for the developer team. They want to change something in the report the app delivers to the clients. We need to change the billing module to satisfy the company&#39;s requirements. This module also has the responsibility to handle generate and store the billings, as well as send reports to the company. Don’t you think it&#39;s doing more than one thing? What if a new need about the company’s report arrives. Would we have to change it again? Well… it surely has a lot of reasons to change.</p><p>Avoiding this kind of problem is a must if we want to have a scalable and maintainable application. The <strong><em>billing</em></strong> module does more than one thing and in consequence, has more than one reason to change. If we do correctly, splitting it into more modules could solve the problem.</p><p>A possible solution would be to extract two different modules for reporting. One from the client perspective and the other from the app owner (our client) perspective where every module consumes data from the <strong><em>billing</em></strong> module. In future updates, adding a column or modifying a row in a report won’t require any changes in other modules.</p><h4>Classes</h4><p>Classes are usually another commonplace for SRP violation. If your project is full of classes named <em>Manager, Engine </em>or<em> Service </em>it would be the first place to look. Let’s see an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edbad4c6a13723d3145ec115906fb2dc/href">https://medium.com/media/edbad4c6a13723d3145ec115906fb2dc/href</a></iframe><p>According to its name, this class manages billing stuff. Yet, it can change because of many reasons (the report changes, something in the payment process changes and so on). Like we did with the module sample, splitting these kinds of classes would solve the problem. You’ll have more classes in your project, but every class will only do one thing and have only one reason to change. Don’t be afraid of creating classes to bring clarity to your project.</p><h4>Methods</h4><p>Wait, did you think you were already done?</p><p>Let’s say that you achieved the SRP with your classes by splitting them into several ones. Now it is time to review your methods as well. We could have more work to do there!</p><p>Whether you are using an MVP or MVVM pattern, a possible Interactor from the <strong>BillingManager</strong> class could be <strong>PayBilling</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1acd51d12dd3213480045ac859610da6/href">https://medium.com/media/1acd51d12dd3213480045ac859610da6/href</a></iframe><p>The public method in this class has some parameters which give us a clue that this method violates the SRP. Yes, it’s the <em>boolean</em> one.</p><p>This kind of parameter forces us to have an if statement to decide which path to take between two possible outcomes. In this case, the decision is whether we have to pay the last billing or pay the billing with the number received in the second parameter. This method does more than one thing.</p><p>A better design would avoid this problem by splitting the method. But, before that, we need to make another change to our class before taking care of the method. When the problem is in the public method of the <strong>Interactor</strong>, it means that the <strong>Interactor</strong> itself has to be split. Creating the <strong>PayLastBilling</strong> and moving all the related code to that class will do the job.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/847cfb0b85a130451b5ab0a13f6a352e/href">https://medium.com/media/847cfb0b85a130451b5ab0a13f6a352e/href</a></iframe><p>Now that we have split the class we can focus on the public method. Splitting the method again would finally solve or problem. We will have two new private methods which will do one simple thing each.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83edce2065dce680837f9309240e9a0d/href">https://medium.com/media/83edce2065dce680837f9309240e9a0d/href</a></iframe><h3>Conclusion</h3><p>We have learned what <strong>SOLID</strong> principles are and why we should apply them all around our apps to keep them flexible, maintainable and better prepared for any future change.</p><p>We agreed that no matter how complex our Android applications are, we can improve our designs by applying the SRP at several levels. At every level, it&#39;s important to have well-defined responsibilities.</p><p>Check the second part of this series in the link below:</p><p><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-two-438022240480">Make your Android application rock SOLID — Open Close</a></p><p>I invite you to check my other posts in my profile too and, as I always say, If you find this article useful please support with a 👏.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba71774f864e" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/make-your-android-application-rock-solid-part-one-ba71774f864e">Make your Android application rock SOLID — Single Responsibility</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigate easily with Navigation Component]]></title>
            <link>https://nogueiras.medium.com/navigate-easily-with-navigation-component-f5251e5ae142?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5251e5ae142</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Mon, 01 Jul 2019 21:18:49 GMT</pubDate>
            <atom:updated>2019-07-31T02:50:48.048Z</atom:updated>
            <content:encoded><![CDATA[<p>What&#39;s new in Navigation Component by example.</p><p>The last month, at <strong>Google I/O 2019</strong>, the Android Jetpack engineers presented to us the latest version of one of the most interesting components, the Navigation Component <strong>2.1.0</strong>.</p><p>This version is still in alpha channel (precisely in <strong>alpha05</strong>) and that&#39;s why I’ve decided to play a little bit with it to be ready for the stable release. Let&#39;s see what&#39;s this all about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*QrMWyW_JPiwIYt00qEYCUw.gif" /><figcaption>Navigation example using a login use-case.</figcaption></figure><h3><strong>What&#39;s Navigation Component?</strong></h3><p>The Navigation Component comes as part of the Android Jetpack, precisely as an Architecture Component. Basically, it completely changes the way we navigate through views in Android, simplifying it by reducing boilerplate and providing a simple API to navigate everywhere in your app regardless of where you currently are. Whatsmore, in most cases you won&#39;t have to worry about managing the stack, the back navigation and of course, all the problems related to committing fragments.</p><p>There are three important components in Navigation which will help us to achieve our navigation aims:</p><ul><li><strong>Navigation Graph: </strong>This graph is where is set all the navigation configuration for a particular <strong><em>NavHost</em></strong>.</li><li><strong>NavHost: </strong>It&#39;s an empty container where navigation will take place. In other words, it is where views will be swapped in and out.</li><li><strong>NavController: </strong>This is the object which will handle all the navigation in our application.</li></ul><h3>Adding the dependencies</h3><p>To start using Navigation we must add the dependencies to our project. It can be found in Google&#39;s Maven Repository.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c7be95f79abb8a77429ab5c18e56857/href">https://medium.com/media/4c7be95f79abb8a77429ab5c18e56857/href</a></iframe><blockquote>I&#39;m using the <strong>buildSrc</strong> module to build the project and that&#39;s why I&#39;ve defined the dependencies like that.</blockquote><p>Add to the app&#39;s gradle file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2e63c66ad657a648fc91fb03613eae0/href">https://medium.com/media/a2e63c66ad657a648fc91fb03613eae0/href</a></iframe><p>This post is completely written for Kotlin users and the example in the repository is also in this beautiful language. But, if your entire project is still in Java (and you do not have any intentions of changing it) there is a Java version of the Navigation library that you can import instead.</p><h3>Defining the Navigation Graph</h3><p>The first thing you need to do after adding the dependencies is to set your navigation graph. As mentioned before, this graph is the place where you define all your navigation structure with its directions, actions, and arguments. It must be added in a <em>navigation folder </em>into the <em>res folder.</em></p><p>Our example has two activities and a dialog (which is the new thing here, in the alpha channel) and several fragments. Let&#39;s take a look at it…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0d0e4f86d62019fb9af65864bf66dc3/href">https://medium.com/media/d0d0e4f86d62019fb9af65864bf66dc3/href</a></iframe><p>You can also create this file using the Android Studio tool for it but the result will be the same. This is how it looks like for our example application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niLO7NxGesOVLPAIX3lTpA.png" /><figcaption>Navigation Graph using Android Studio tool</figcaption></figure><p>The interesting thing here is that we are able to see a preview of our views in the graph as we can appreciate in the previous image. This is very useful when we are designing our application due to it shows us a complete panoramic picture of the section we are working on.</p><p>If you haven&#39;t generated some view but you want to set a navigation action for designing purposes, you can use the <em>blankFragment </em>provided in the library.</p><p>The <em>loginFragment</em> has a little house icon associated with its name meaning that this is the start destination of the navigation graph. You can set and change this by selecting the fragment in the Android Studio and pressing the little house button in the upper menu or you can make it in the old way by setting the <strong>app:startDestination </strong>in the navigation tag of your graph.</p><p>Every navigation graph has a <strong>Navigation Host</strong> associated. In this case, the <em>LoginActivity </em>contains the login&#39;s navigation host. This navigation host is a <em>fragment tag</em> which you can constraint to any view like any other known view types (and customs) in Android. All the transitions will occur in there, no matter the space, no matter the final position of the host.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a926a08ef45c3a4b3424618f08b517a/href">https://medium.com/media/1a926a08ef45c3a4b3424618f08b517a/href</a></iframe><p>Let&#39;s pay special attention to the <strong><em>defaultNavHost </em></strong>value that we have set in true. This means that in case we have multiple navigation hosts in the same layout, this is the one which the system will use to handle the back action when navigates. One and just one of them can be set to true.</p><p>Once added several fragments to our graph, it&#39;s time to connect them. To achieve this we have <strong><em>actions</em></strong>. Actions allow us to define a destination to navigate in a very simple and concrete way. This is the action defined to navigate from our <em>loginFragment</em> to our <em>recoveryPasswordFragment:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5895a401d2cecb3d9823e6ad9ceec786/href">https://medium.com/media/5895a401d2cecb3d9823e6ad9ceec786/href</a></iframe><p>The action&#39;s id is what you are gonna use to tell the navigator that navigates to the destination defined below. Destination&#39;s id is a custom id that you have already set on the destination tag, into the navigation file. This action has to be contained into the fragment, activity or dialog from where you need to navigate from. You can set several actions over the same fragment to navigate different places and it&#39;s just that easy as it seems.</p><h4>Navigate using the action defined</h4><p>After defining your action in the navigation graph (a thing you can also aim by connecting both views through arrows using the Android Studio tool) and in order to perform the navigation itself, you need to set up your <strong>NavController</strong>.</p><p>You can obtain an instance of this object every time you need to use it or, knowing you will use it all around your fragment, you can get an instance after the view is created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bf48c483045ba66c63c06becd93012c/href">https://medium.com/media/4bf48c483045ba66c63c06becd93012c/href</a></iframe><p>Now, to navigate to the recover password fragment, when the user clicks on the text button just use the instance of the <strong>NavController </strong>that we&#39;ve already saved and call the navigate method with the id defined in the action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d51de25d364822a0439da06e4ab7223/href">https://medium.com/media/2d51de25d364822a0439da06e4ab7223/href</a></iframe><h3>Sending Arguments</h3><p>We have talked about navigation between destinations but, what we haven&#39;t talked about yet is passing arguments (or extras if the destination is an Activity).<br>There are two different ways to pass data when navigates with Navigation Component. Let&#39;s see them.</p><h4>Bundle</h4><p>As we all should know, to send data through activities and fragments (or vice versa) you must create a Bundle. Therefore, to send data to different destinations using Navigation Component you can use a Bundle too.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a50bd783b89e3601a97e573a705c549/href">https://medium.com/media/4a50bd783b89e3601a97e573a705c549/href</a></iframe><p>In your destination, whether it be a fragment or an activity, the <em>loggedUser </em>must be recovered as usual.</p><h4>SafeArgs</h4><p>SafeArgs is a new way to pass data between destinations with a great advantage against traditional Bundle, type safety. Basically, it&#39;s a plugin that generates classes to pass and extract data between destinations.</p><p>To use it, add the plugin to your classpath:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f88ceedcedaea5c450e1053d39e7675/href">https://medium.com/media/2f88ceedcedaea5c450e1053d39e7675/href</a></iframe><p>and apply it to your app main module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a89110c86980c4e4535daf383e072f78/href">https://medium.com/media/a89110c86980c4e4535daf383e072f78/href</a></iframe><p>The plugin will generate classes for every destination in the project and will create typed factory methods to pass data through it. These classes have the view&#39;s name with the <strong>Directions</strong> suffix and the factory methods will be named as the <strong>action</strong>. Next, navigate using the destination object it creates instead of using the <strong><em>actionId</em></strong>. But, in order to generate these classes, the plugin needs that we specify the arguments in the destination we need to pass the data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bea588ff966432aed38eaaa7e0cdaf90/href">https://medium.com/media/bea588ff966432aed38eaaa7e0cdaf90/href</a></iframe><p>This argument must have a name and an argument type, the last of course, for the plugin to create the helpers. The argument type can be of several types, including <strong>Serializable</strong> and <strong>Parcelable</strong>. Full types can be checked <a href="https://developer.android.com/guide/navigation/navigation-pass-data#supported_argument_types">here</a>.</p><p>This is how navigates using safeArgs helpers classes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6075770470169dfbfbd57a71777a066/href">https://medium.com/media/c6075770470169dfbfbd57a71777a066/href</a></iframe><p>And this is how you recover the data in the destination:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea1b39b3ca32caebfb2332c08bbe2afc/href">https://medium.com/media/ea1b39b3ca32caebfb2332c08bbe2afc/href</a></iframe><p>As you see, the plugin also generates classes to recover the data. These classes will be named as the destination plus the Args suffix.</p><h4>ProGuard considerations</h4><p>If you are using <strong>ProGuard</strong> you must add rules to keep the <strong>Serializable</strong>, <strong>Parcelable</strong> and <strong>Enum</strong> used as arguments out of being modified. This can be achieved using the @Keep annotation or adding the rule in the ProGuard file.</p><h4>Navigating to Dialogs</h4><p>The current navigation version adds also the possibility to navigate to dialogs just as you do with fragments or activities, and from them to other directions. Just replace the fragment tag for a dialog tag, change the <strong><em>app:name</em></strong> attribute with the dialog full name and that&#39;s all.</p><h4>Deeplinking</h4><p>DeepLinking has never been so easy as with the Navigation Component. You just need to specify the deeplink in your destination, add some code in manifest and that&#39;s all.</p><p>I&#39;ll be covering these topics in future application updates.</p><h3>Final thoughts</h3><p>Navigation in Android applications is becoming a very easy task with Navigation Component. If you are planning to add it to your application I&#39;ll suggest starting from now. Just remember that you&#39;ll need to wait a little bit to use the navigation to dialogs in production code because it&#39;s still in the alpha channel.</p><p>I’ll be updating the application to cover more navigation cases and adding additional examples. All suggestions are welcome.<br>If you found this post useful, please support it with a 👏 .</p><p>Full Github repository can be found in the link above.</p><p><a href="https://github.com/nogueirasjorge/navigation-example">nogueirasjorge/navigation-example</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5251e5ae142" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Overview to Google I/O '19]]></title>
            <link>https://medium.com/etermax-technology/google-io-by-etermax-a0bb1add76fb?source=rss-42aca0245b67------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0bb1add76fb</guid>
            <category><![CDATA[google-io-2019]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android-q]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jorge Nicolás Nogueiras]]></dc:creator>
            <pubDate>Mon, 20 May 2019 17:18:59 GMT</pubDate>
            <atom:updated>2019-05-21T18:21:41.726Z</atom:updated>
            <content:encoded><![CDATA[<h3>An Overview to Google I/O ’19</h3><p>Etermax attended this year edition and tells you all about the biggest technology event around the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5Q5WDbtUC_Qw_QPpPPXoQ.png" /></figure><p><strong>Google I/O</strong> &#39;<strong>19 </strong>finished and in <a href="https://engineering.etermax.com/"><strong>Etermax</strong></a><strong> </strong>we are very excited about all the announcements and new tools in which <strong>Google</strong> has been working on. Our expectations were high having participated in previous editions announcements and they did not disappoint us at all.</p><h3>Hey Google, Let&#39;s play Trivia Crack!</h3><p>Etermax, as a game company, feels very proud every time that one of its games entertain new audiences around the world. We are excited to announce that <a href="https://assistant.google.com/services/a/uid/000000ad1657763e">Trivia Crack</a> is the most played game in Google Assistant today. Find Trivia Crack in Assistance and try it by yourself just asking “Hey Google, let&#39;s play Trivia Crack&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*DH9sfOuk6Nm5067aCXZglg.jpeg" /><figcaption>Trivia Crack (Preguntados) available to play on Google Assistance</figcaption></figure><h3>Google Keynote</h3><p>The Keynote was full of announcements about accessibility and augmented reality. With the power of <a href="https://lens.google.com/">Lens</a> and working with some partners they were capable to do, in example, that our food orders be easy and accessible as much as renting a car or a flat for a few days.</p><p>Now, you can select more wisely your meal in a restaurant by pointing your camera over the menu and see it becoming alive to tell you what is your selection about, give some recommendations and even calculate the tip on the your check, all with your phone.</p><p>Whether you are not capable to read some text from an important sign in the street or you just need to understand sensible information in a different language, you can also use Google Lens for a live translation in your screen and audible too.</p><p>There are some great news in <a href="http://maps.google.com/">Google Maps</a> with augmented reality too. Can you imagine yourself navigating through the streets like if you were really into your phone? Fine, you don&#39;t need to imagine it anymore! Try it right now directly from your Pixel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*YwFOSOhNKkBvxMxWW_vf_g.png" /><figcaption>Google Maps navigation using augmented reality</figcaption></figure><p><strong>Google Assistant</strong> comes with excellent advances in the way we <em>“get things done”</em>. They call new Assistant version as the <strong>“Next Generation Assistance”</strong>. On Pixel devices you will be able to talk the assistance fluidly and it will follow your commands like it would be a real conversation. Moreover, the assistant will maintain the context of your previous actions when you request something new.</p><p>New Drive Mode is also a very useful feature. Once in your car, you can handle the drive by just using your voice. The assistant will suggest places according your reservations, remember paused podcasts you can resume and, the most important thing, if you receive a call, it will ask you if you want to take the call or not.</p><p><strong>Google</strong> is one of the companies that invest effort and resources working with those who have all kind of problems and incapabilities, trying to use technology to improve their life. That&#39;s why they had introduced Live Caption; a new single-button option which will enable caption on every video, podcast or moment. This makes audible things, also be readable. And the best is that this works completely offline, on the device with <strong>Android Q</strong>. <em>Qte, right?</em></p><p>Android Q is what we all were waiting for, and of course, it comes with some improvements about Security and Privacy. Users will be able to grant more granular permissions to apps, as Location, by allowing them to use it while running the app, always or never.</p><p>However, one of the most waited for all users around the world is <strong>Dark Mode</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MqfNVp6gqcsxFMMYo549PA.png" /><figcaption>New Dark Mode on Android Q</figcaption></figure><p>The only thing we must do as developers is to follow some guidelines and Android Q will just do the job for us. If you are one of those devs who can&#39;t wait to the final release, you can always enroll yourself into the beta program.</p><p>5G will be available soon and Android Q has full support for this new generation of mobile network. Although this technology will be used by lot of people in 2020, Android prepares itself for the arriving.</p><h4>Kotlin comes first</h4><p>Besides the imminent release of Android Q, this should be the most exciting announcement on software development this year: <strong>Kotlin comes first</strong>. But, what does this mean? How Kotlin will come first? Well… you&#39;ll see a lot of Kotlin code on new versions of Android Jetpack, like <strong>Navigation</strong>, <strong>DataBinding</strong> and <strong>ConstraintLayout</strong>. They will keep providing support for Java developers, but we shouldn&#39;t see any new feature written in Java. What&#39;s more, some component in Jetpack will be supporting kotlin coroutines, as well as RxJava.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NsetH83WT9VJB4p4gwgZSw.png" /><figcaption>Kotlin Everywhere flyer</figcaption></figure><p>A new series of events will be hosted around the world for those who love kotlin and want to know all about it. This events will be called <strong>Kotlin / Everywhere</strong> and you will be able to join them between June and December 2019.</p><h4>Machine Learning from Zero to Hero</h4><p>We highly recommend this <a href="https://www.youtube.com/watch?v=VwVg9jCtqaU">talk</a> if you always wanted to know what does machine learning means and how does it work but you didn&#39;t know where to start.</p><p>Incredible new things could be achieved using machine learning combined with ARCore since its launch but this year, Google has duplicated efforts and created a Lite version of its TensorFlow, <strong>TensorFlow Lite</strong>. With this, you train your model on TensorFlow and download it to run it offline on your project. This makes, for example, object recognition faster because the inference is made locally on user&#39;s device. This technology is currently available for Android, however Google engineers are working on a Swift version of TensorFlow.</p><h3>Tools, Components and… more Kotlin</h3><p>As we mentioned before, Google decided that <strong>Kotlin comes first</strong> but that’s not the only thing they had decided this year. The engineers teams focused on making the development tools and libraries more robust, less buggy and kotlin friendly.</p><h4>Android Jetpack</h4><p>Compose is a new tool to design your views directly from the code avoiding the double file existance <em>(xml/kt). </em>This isn&#39;t new to Flutter developers because the idea of this feature was inspired from there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acf8f04afc12688093707c9491223984/href">https://medium.com/media/acf8f04afc12688093707c9491223984/href</a></iframe><p>Compose is not currently available but we will see a lot of discussion about it in the next months until its final release.</p><h4>Constraint Layout 2.0.0 … -alpha</h4><p>This I/O edition present us a great improvement over <strong>ConstraintLayout</strong>. For those who don’t use it (or worse, don’t know about it) let me tell you that this is something you don&#39;t wanna miss. It&#39;s a great tool to make your layouts lightweight, performant and understandable.</p><p>But, why are we so excited about this new release? The answer is…</p><h4>MotionLayout</h4><p>MotionLayout is a completely new tool to animate your views. You can add transitions, movements, combine elements, change its properties and also, combine different MotionLayouts to create even more beautiful and original animations.</p><p>With this, the team behind ConstraintLayout 2.0 created new Helpers to allow developers code more understandable and reusable views. You can use the provided Helpers (like Flows) or create your owns.</p><p>All this new features and improvements have their respective tools which will be available onto the upcoming Android Studio 3.5. Navigation flows will be very easy to create and maintain, Resource Manager comes with optimizations and features, Profiler has new Power Consumption analysis and of course, the general optimizations and bug fixing we all were waiting for.</p><p>One more year has passed and one more time Etermax came back from Google I/O with its expectations met, renewed energies and prepared to create good products and <em>get things done.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0bb1add76fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/etermax-technology/google-io-by-etermax-a0bb1add76fb">An Overview to Google I/O &#39;19</a> was originally published in <a href="https://medium.com/etermax-technology">etermax technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>