<?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 Priyank Kumar on Medium]]></title>
        <description><![CDATA[Stories by Priyank Kumar on Medium]]></description>
        <link>https://medium.com/@pypriyank?source=rss-7f15b3f07bd8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*fOFpEIBez-LoAMGlFhQcig.png</url>
            <title>Stories by Priyank Kumar on Medium</title>
            <link>https://medium.com/@pypriyank?source=rss-7f15b3f07bd8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 14:51:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pypriyank/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[Reactive Programming in Android using RxJava and RxAndroid]]></title>
            <link>https://medium.com/@pypriyank/reactive-programming-in-android-using-rxjava-and-rxandroid-706035fab94f?source=rss-7f15b3f07bd8------2</link>
            <guid isPermaLink="false">https://medium.com/p/706035fab94f</guid>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[rxandroid]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Priyank Kumar]]></dc:creator>
            <pubDate>Mon, 04 May 2020 02:06:27 GMT</pubDate>
            <atom:updated>2020-05-04T02:06:27.401Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zAUXgFvNSbJGRvXLIlyuEw.jpeg" /></figure><p>RxJava is nothing new and had been around for quite some time now. If you have heard of it and haven’t started yet, then let’s take a quick into the realm of the Reactive Programming paradigm and understand the basic concept so you can use RxJava in your Android projects in no time. Reactive programming can be a significant shift for programmers who are coming from the Imperative programming paradigm. Some reasons include there is no concept of mutable state in Reactive Programming; Imperative programming focuses on callstack while Reactive reacts to events, and written ignorant of time and context.</p><h3>What is Reactive Programming?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*vbMb4HBtN_rwsb3YlBxrDg.png" /></figure><p>The word “Reactive” had been a buzz word this decade in the world of programming and makes every thing sound cooler. Here’s how <a href="https://en.wikipedia.org/wiki/Reactive_programming">Wikipedia</a> defines Reactive Programming:</p><blockquote>In <a href="https://en.wikipedia.org/wiki/Computing">computing</a>, <strong>reactive programming</strong> is a <a href="https://en.wikipedia.org/wiki/Declarative_programming">declarative</a> <a href="https://en.wikipedia.org/wiki/Programming_paradigm">programming paradigm</a> concerned with <a href="https://en.wikipedia.org/wiki/Stream_(computing)">data streams</a> and the propagation of change. With this paradigm it is possible to express static (e.g., arrays) or dynamic (e.g., event emitters) <em>data streams</em> with ease, and also communicate that an inferred dependency within the associated <em>execution model</em> exists, which facilitates the automatic propagation of the changed data flow.</blockquote><p>Now, let understand this from a simple example</p><h3>Getting Started</h3><p>Before getting started, we need to add a couple of dependencies. As of now the latest version of dependencies or Rxjava and RxAndroid are:</p><pre>dependencies {<br>    implementation &#39;io.reactivex.rxjava3:rxandroid:3.0.0&#39;<br>    implementation &#39;io.reactivex.rxjava3:rxjava:3.0.3&#39;<br>}<br>// Get updated version from <a href="https://github.com/ReactiveX/RxAndroid">Offical Gitub page</a>.</pre><p>For demonstration, we are going to make a simple app to display a list of movies along with its genre and release year. Now we are going to add a few more dependencies to make our job easier like “<a href="https://github.com/JakeWharton/butterknife">Butter Knife</a>”, “<a href="https://github.com/JakeWharton/RxBinding">RxBinding</a>” for data binding. Here’s what else you need to paste your build.gradle (Module:app):</p><pre>implementation &#39;com.jakewharton:butterknife:10.2.1&#39;<br>annotationProcessor &#39;com.jakewharton:butterknife-compiler:10.2.1&#39;<br><br>implementation &#39;com.jakewharton.rxbinding3:rxbinding:3.1.0&#39;<br>implementation &#39;com.jakewharton.rxbinding3:rxbinding-recyclerview:3.1.0&#39;<br>implementation &quot;androidx.cardview:cardview:1.0.0&quot;</pre><p>Make sure you sync your project after doing that.</p><p>I am not going to use retrofit or DAO to stay on topic; instead, I am going to use some hard-coded data. So let’s get started by creating our layout. Let’s start with activity_main.xml.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad80904ed98f9fab954671037ce80690/href">https://medium.com/media/ad80904ed98f9fab954671037ce80690/href</a></iframe><p>Onto our MainActiviy.java, let’s write code to bind and add data to our UI.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34cc140edfa3a906dad927b4fcea2a91/href">https://medium.com/media/34cc140edfa3a906dad927b4fcea2a91/href</a></iframe><p>Now run your project, you must be getting a result like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irti7VKkpJOA7eg-xyE8Ww.png" /></figure><p>This was like a hello world of RxJava and RxAndroid. Now let do something slight complex. Now let do something slight complex. We are going to display a list of movies in a RecyclerView we created in our activity_main.xml layout. Before creating an Adapter class for out RecyclerView create a class for our Movie object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcf0df5249abf6586596bf9acc49574b/href">https://medium.com/media/bcf0df5249abf6586596bf9acc49574b/href</a></iframe><p>Our RecyclerView adapter needs a layout for a single item (Movie in this case) to inflate or parent ViewHolder. Let’s use CardView to create that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3e21436ee2202e299333b922313ad33/href">https://medium.com/media/f3e21436ee2202e299333b922313ad33/href</a></iframe><p>Now we create our Adapter class for our RecyclerView.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcee38947366702938abe784eb6a576f/href">https://medium.com/media/fcee38947366702938abe784eb6a576f/href</a></iframe><p>Finally, we update our MainActivity.java.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce2a2e0a27fef61d17672d9acf5be624/href">https://medium.com/media/ce2a2e0a27fef61d17672d9acf5be624/href</a></iframe><p>After making all above change our app should look quite like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rFGKkXFKsj6t59H290-Mhg.png" /></figure><h3>That’s all, For now!</h3><p>This was a brief over view of using RxJava and RxAndroid in our project. Hope this helps you get started with reactive programming in android. I will be writing more on similar topic and complex approaches with RxAndroid in upcoming weeks. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=706035fab94f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WorkManager for efficient background works in Android]]></title>
            <link>https://medium.com/@pypriyank/workmanager-for-efficient-background-works-in-android-41a537fbae1f?source=rss-7f15b3f07bd8------2</link>
            <guid isPermaLink="false">https://medium.com/p/41a537fbae1f</guid>
            <category><![CDATA[workmanager]]></category>
            <category><![CDATA[background-service]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Priyank Kumar]]></dc:creator>
            <pubDate>Mon, 27 Apr 2020 03:23:56 GMT</pubDate>
            <atom:updated>2020-04-27T03:23:56.703Z</atom:updated>
            <content:encoded><![CDATA[<p>As a developer, you know the importance of working in the background; some of the app’s background tasks must run, even if the user minimizes or reboots the app. It could be a task like syncing data, downloading updates. There are several APIs to do this (like AsyncTask, JobScheduler, AlarmManager, Service, Firebase JobDispatcher, etc.), and each has its use cases. But there is a drawback of using these APIs in a wrong way leads to quick drainage of battery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*6U-HXSz4Oi7Pe0nbfXUAbg.jpeg" /></figure><p>Android has introduced several features (like Doze, BackgroundService, App Standby Buckets, etc.) to avoid such atrocity. Developers must work with these battery-saving features and also need to make sure they work aptly on all available API levels, which add some code complexity. Not caring about different API levels may lead to our background work, not running for all users.</p><p>How we target different API versions:</p><pre>if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>O</em>) {</pre><pre>    // This block runs only for Android Oreo and above.</pre><pre>} else if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.M) {</pre><pre>    // This block runs for Android Marshmallow </pre><pre>} else if (...) {<br>    <br>    // and so on ...</pre><pre>}</pre><h3>Enters WorkManager</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*677KXyRwpAq6ohbLQHNbwA.png" /></figure><p>WorkManager provides a unified solution for background works, keeping the client’s API level into account.</p><h4>Definition:</h4><blockquote>WorkManager is a library for managing deferrable and guarantee background work.</blockquote><p>It’s backward compatible till API level 14, it is a part of the android jetpack and runs with our without Google Play Services.</p><p>Ideally, WorkManager is best suited for background works that are deferrable (tasks that can run later but still useful) and guaranteed (tasks that run even if the device reboots) to run. For example, uploading a crash report is a suitable candidate for WorkManager; on the other hand, sending a text message is not an appropriate task for WorkManager because it is not deferrable.</p><p>Let’s get started with WorkManager with a quick example. We need to add WorkManger as our Gradle app-level dependency. So, to our build.gradle we will add:</p><pre>def work_version = &quot;2.3.4&quot;<br><br>// (Java only)<br>implementation &quot;androidx.work:work-runtime:$work_version&quot;</pre><p>Now, as for the background work we want to do, we will create a separate class and inherit Worker to that class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e503a1b548f62d3ae37f68e475ae67d7/href">https://medium.com/media/e503a1b548f62d3ae37f68e475ae67d7/href</a></iframe><p>I have use Thread.sleep to stimulate a time-consuming process. Let’s create the data, constraints and request for out WorkManager.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38ec20b5e73075a406bfcf4ecb0bcdcb/href">https://medium.com/media/38ec20b5e73075a406bfcf4ecb0bcdcb/href</a></iframe><p>WorkManager is not a replacement for the API used to do background task, but help tremendously when it comes to integrating them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41a537fbae1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Notification Services in Android O and Above]]></title>
            <link>https://levelup.gitconnected.com/showing-notifications-is-one-of-the-very-crucial-feature-to-add-in-an-android-app-4b7ada5bdba7?source=rss-7f15b3f07bd8------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b7ada5bdba7</guid>
            <category><![CDATA[notifications]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[notification-service]]></category>
            <dc:creator><![CDATA[Priyank Kumar]]></dc:creator>
            <pubDate>Mon, 20 Apr 2020 02:16:34 GMT</pubDate>
            <atom:updated>2020-04-25T22:02:46.875Z</atom:updated>
            <content:encoded><![CDATA[<p>Showing notifications is one of the very crucial features to add in an android app. It is the responsibility of us as developers to give timely and relevant information to our users. Also keeping in our mind that our users do not get annoyed by the notifications. An Android engineer on the system UI gave the following quote:</p><blockquote>“Don’t annoy the user. Respect them. Empower them. Delight them.</blockquote><blockquote>Connect them to the people they care about.”</blockquote><blockquote>~ Dr Christopher R. Wren</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*X1NK01rRPWifcdR5dnKR7w.jpeg" /></figure><p>We are going to target Android O and later, and to do that we need to know three following things to send notifications.</p><ol><li><a href="https://developer.android.com/reference/android/app/NotificationChannel">Notification Channel</a></li><li>Notification Builder</li><li>Notification Manager</li></ol><h3>Notification Channel</h3><p>Notification Channel requires an id, name, and description, which we are going to define as “private static final String”.</p><pre>public static final String <em>CHANNEL_ID </em>= &quot;channel123&quot;;<br>public static final String <em>CHANNEL_NAME </em>= &quot;my notification&quot;;<br>public static final String <em>CHANNEL_DESCRIPTION </em>= &quot;Test&quot;;</pre><p>Now to create our channel, we will use the class NotificationChannel to create a new NotificationChannel object (channel), and we will pass channel id, name, and importance to the constructor. Then we will set a description to our channel calling setDescription method on our channel object.</p><pre>NotificationChannel <strong>channel</strong> = new NotificationChannel(<br>                <strong><em>CHANNEL_ID</em></strong>,<br>                <strong><em>CHANNEL_NAME</em></strong>,<br>                NotificationManager.<em>IMPORTANCE_DEFAULT<br>        </em>);<br><strong>channel</strong>.setDescription(<em>CHANNEL_DESCRIPTION</em>);</pre><h3>Notification Builder</h3><p>We will use NotificationCompat.Builder class to create our notification builder object (mBuilder). Now we will pass the context and the channel id to the constructor. Then we also chain several method on to our constructor to add more information, like setSmallIcon to add icon (Most likely a <a href="https://medium.com/@pypriyank/vector-assets-powerful-way-to-create-icons-and-menu-items-in-android-c28b469a7c9b">vector drawable</a> asset), setContentTitle to add title for our notification, setContentText to give body to our notification, most importantly we must add setPriority method to assign the priority the notification we want to pass to the user. Setting priority allows android to set the kind of alert to give to the users.</p><pre>NotificationCompat.Builder <strong>mBuilder</strong> =<br>        new NotificationCompat.Builder(this, <strong><em>CHANNEL_ID</em></strong>)<br>            .<strong>setSmallIcon</strong>(R.drawable.<em>ic_fiber_new_black_24dp</em>)<br>            .<strong>setContentTitle</strong>(&quot;Hello, attention!&quot;)<br>            .<strong>setContentText</strong>(&quot;Here&#39;s the notification you were looking for!&quot;)<br>            .<strong>setPriority</strong>(NotificationCompat.<em>PRIORITY_DEFAULT</em>);</pre><h3>Notification Manager</h3><p>Notification manager object is used to create the channel and notify the user. It is done in two part, first the creation of our notification channel object, to do that we use NotificationManager object and user setSystemService(NotificationManager.class) to create the object (say manager). Then we will call createNotificationChannel method on our manager object and pass the channel object to it.</p><pre>NotificationManager <strong>manager</strong> = getSystemService(NotificationManager.class);<br><strong>manager</strong>.createNotificationChannel(<strong>channel</strong>);</pre><p>Secondly, we notify user by using the class NotifyManagerCompat, and we create the <strong>object</strong> by calling “<strong>from</strong>” method on our NotifyManagerCompat class (<strong>mNotificationManager</strong>). The to the mNotificationManager object we call notify method with <strong>id</strong>, and<strong> mBuilder.build()</strong> as an argument to send the notification.</p><pre>NotificationManagerCompat <strong>mNotificationManager</strong> = NotificationManagerCompat.<strong><em>from</em></strong>(this);<br>mNotificationManager.<strong>notify</strong>(1, <strong>mBuilder</strong>.build());</pre><h3>Send notification on a click of a button</h3><p>For simplicity, we will start by showing notification on the click of a button. So to our layout we will add a button to our activity_main.xml. Here’s how my XML looks like:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    tools:context=&quot;.MainActivity&quot;&gt;<br><br>    &lt;Button<br>        android:id=&quot;@+id/btn_notify&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:text=&quot;@string/notify_me&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;<br><br>&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;</pre><p>You can see we have added an id to our button so that we can call in our java code and setOnClickListener on it.</p><p>Here’s how our code looks like after implementing all about concepts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ceb60571a21bb386d9f87e5758d9c8f/href">https://medium.com/media/5ceb60571a21bb386d9f87e5758d9c8f/href</a></iframe><p>Now our little app is ready for test. So when we run our app and click on the button we placed you will hear an alert tone and a notification popping up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zm-rM-8gQc9FuNZbec-r3Q.png" /></figure><p>Now, showing notification right after the user clicks the button is not a very practical use case, so next we will see how to set a remainder to show notification after certain amount of time and must notify even if our app is closed.</p><h3>Show notification for the set remainder</h3><p>To show the notification after certain period and show notifications even if our app is closed are the two additional features we’re going to add. First let see how we are going to show notifications even if our app is closed. So, we are going to use <strong>BroadcastReciever</strong> that. We will create a separate class that extends BroadcastReciever and will build our notification in that class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dcbc8ad1ed75edc05ac23289f913dcc/href">https://medium.com/media/6dcbc8ad1ed75edc05ac23289f913dcc/href</a></iframe><p>Then to our android manifest we will add our broadcast reciever to the ReminderBroadcast class.</p><p>Add following inside &lt;application&gt; in AndroidManifest.xml file:</p><pre>&lt;receiver android:name=&quot;.ReminderBroadcast&quot; /&gt;</pre><p>Now to send notification after a certain amount of time after the button click we will first create object of Intent and PendingIntent:</p><pre>Intent intent = <br>          new Intent(MainActivity.this, ReminderBroadcast.class);<br>PendingIntent pendingIntent = PendingIntent<br>          .<em>getBroadcast</em>(MainActivity.this, 0, intent, 0);</pre><p>Then we will use AlarmManager class to set up the trigger for our notification, here in our example we took 10 mili-second but of course you can take any amout you want, or you can easily get the value from user.</p><pre>AlarmManager alarmManager = (AlarmManager) getSystemService(<em>ALARM_SERVICE</em>);<br><br>long currentTime = System.<em>currentTimeMillis</em>();<br>long timeInterval = 1000 * 10;        // = 10 seconds //<br><br>alarmManager.set(AlarmManager.<em>RTC_WAKEUP</em>, currentTime + timeInterval, pendingIntent);</pre><p>Now our app is good to go, and here’s how our MainActivity.java looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a916474c0fe8a1b098b4853dd100e0a4/href">https://medium.com/media/a916474c0fe8a1b098b4853dd100e0a4/href</a></iframe><p>Now whenever user clicks on the button the notification will pop up after ten second. Using this concept you can create notification for your own android app. But make sure to use these features wisely.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b7ada5bdba7" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/showing-notifications-is-one-of-the-very-crucial-feature-to-add-in-an-android-app-4b7ada5bdba7">Notification Services in Android O and Above</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding MVVM Architecture  in Android]]></title>
            <link>https://medium.com/swlh/understanding-mvvm-architecture-in-android-aa66f7e1a70b?source=rss-7f15b3f07bd8------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa66f7e1a70b</guid>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Priyank Kumar]]></dc:creator>
            <pubDate>Sat, 11 Apr 2020 08:43:47 GMT</pubDate>
            <atom:updated>2020-04-25T10:36:48.866Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding MVVM Architecture in Android</h3><p>You know the importance of architecture and design pattern if you have worked on any intermediate and high-level projects. It is essential to keep our project loosely coupled; which means keeping all the components in our project separate, meaning each component has little or no knowledge about the others. This is especially important in big projects because things get messy quite quickly, and the end-result is unmaintainable. These spaghetti codes (Tightly coupled) is also difficult to test because many different parts depend on each other. That’s why we have architecture patterns to make our project modular, where each component have a specific responsibility and modifications are possible without modifying other modules.</p><p>There are several different architectural patterns to choose from, here are some of the popular ones you may have heard about,</p><ul><li>MVC</li><li>MVP</li><li>MVVM</li></ul><p>In android, we can use any one of the above as each has their own advantages and disadvantages (which we are not going to discuss here). But it is highly recommended by google and android developers team to use MVVM architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zgQrDaNwoong7pX9mX8lww.png" /></figure><p>MVVM stands for Model-View-ViewModel architecture. There are several advantages of using MVVM in your projects, such as:</p><ul><li>Makes the project loosely coupled.</li><li>Easier to maintain.</li><li>Simple to add a new feature or remove existing.</li><li>Very testable code.</li><li>It gives great structure to your project and makes it easier to navigate and understand our code.</li></ul><p>Now, there are quite a few frameworks that can help us implement MVVM. Which one should you use in case you don’t want to make your own?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*6_ojYXRx1U7F8moQFQXYTQ.png" /><figcaption>Source: <a href="https://community.devexpress.com/blogs/wpf/archive/2014/04/23/devexpress-mvvm-framework-coming-soon-in-v14-1.aspx?CommentPosted=true">DevExpress</a> interpretation of <a href="https://xkcd.com/927/">XKCD Comics</a></figcaption></figure><p>Google provides its framework comprised of several different components that you can use and build upon to make your job simpler.</p><p>This is how Google’s implementation of MVVM architecture looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*BqFy9rd2_hCtOeHgUY72gg.png" /></figure><h3>View</h3><p>This part of our architecture help us build our user interface and the only part our users can interact directly. I consist of Fragment object defined in “src” and a layout resource. There is a two-way binding between them, which allows easy data sharing.</p><p>Here’s an example, you don’t need to understand each line, only go through their implementations.</p><pre><strong>Fragment :<br>view/MovieFragment.java</strong></pre><pre>public class MovieFragment extends Fragment {<br>    OnPosterClickListener mCallback;<br>    GridView moviesLayout;<br>    List&lt;Movie&gt; movies;<br><br>    public MovieFragment() {<br>    }<br><br>    public MovieFragment(List&lt;Movie&gt; movies) {<br>        this.movies = movies;<br>    }<br><br>    public interface OnPosterClickListener {<br>        void onImageClick(Movie movie);<br>    }<br><br>    @Override<br>    public void onAttach(@NonNull Context context) {<br>        super.onAttach(context);<br>        try {<br>            mCallback = (OnPosterClickListener) context;<br>        } catch (ClassCastException e) {<br>            throw new ClassCastException();<br>        }<br>    }<br><br>    @Nullable<br>    @Override<br>    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {<br>        final View rootView = inflater.inflate(<br>            //Inflating fragment with the layout<br>                R.layout.<em>fragment_movie_list</em>, container, false);<br>        moviesLayout = rootView.findViewById(R.id.<em>images_grid_view</em>);<br>        MovieRecyclerViewAdapter mMovieAdapter = new<br>                MovieRecyclerViewAdapter(getContext(), movies);<br><br>        moviesLayout.setAdapter(mMovieAdapter);<br>        moviesLayout.setOnItemClickListener((<br>              (parent, view, position, id) -&gt;<br>                mCallback.onImageClick(movies.get(position))<br>        ));<br>        return rootView;<br>    }<br>}</pre><pre><strong>Layout:<br>res/fragment_movie_list.xml</strong></pre><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;&gt;</pre><pre>&lt;androidx.recyclerview.widget.RecyclerView<br>        android:id=&quot;@+id/movie_recycler_view&quot;<br>        android:name=&quot;com.example.moviereviewer.MovieFragment&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;0dp&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toBottomOf=&quot;@+id/toolbar&quot; /&gt;<br><br>&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;</pre><h3><strong>ViewModel</strong></h3><p>ViewModel object acts as an intermediate between View and the Model, meaning it provides data for the UI components like fragments or activities. It also includes an observable data holder called LiveData that allows ViewModel to inform or update the View whenever the data get updated. It is very crucial, mainly to keep our app from reloading on orientation changes. Which ultimately provides a great user experience.</p><p>Here’s an example,</p><pre>// viewmodel/MovieModelView.java</pre><pre>public class MovieViewModel extends AndroidViewModel {<br><br>    private static final String <em>DEFAULT_FILTER </em>= &quot;popular&quot;;<br>    private MovieRepository movieRepository;<br>    private LiveData&lt;TMDB_Response&gt; movieList = <br>        new MutableLiveData&lt;&gt;();<br>    private MutableLiveData&lt;TrailerResponse&gt; trailerList = <br>        new MutableLiveData&lt;&gt;();<br>    private MutableLiveData&lt;ReviewResponse&gt; reviewList = <br>        new MutableLiveData&lt;&gt;();<br>    private MutableLiveData&lt;String&gt; filter =<br>        new MutableLiveData&lt;&gt;();<br><br>    public MovieViewModel(@NonNull Application application) {<br>        super(application);<br>        filter.setValue(<em>DEFAULT_FILTER</em>);<br>        movieRepository = new MovieRepository(application);<br>    }<br>    public void setFilter(String value) {<br>        filter.setValue(value);<br>    }<br><br>    public String getFilter() {<br>        return filter.getValue();<br>    }<br><br>    public LiveData&lt;MovieResponse&gt; getMovieList(int pageNo) {<br>        movieList = Transformations.<em>switchMap</em>(filter, <br>             (v) -&gt; movieRepository.getMovieList(v, pageNo));<br>        return movieList;<br>    }<br><br>    public LiveData&lt;TrailerResponse&gt; getTrailerList(int movieId) {<br>        trailerList = movieRepository.getTrailerList(movieId);<br>        return trailerList;<br>    }<br><br>    public LiveData&lt;ReviewResponse&gt; getReviewList(int movieId) {<br>        reviewList = movieRepository.getReviewList(movieId);<br>        return reviewList;<br>    }<br>}</pre><h3>Model</h3><p>Model is responsible for fetching the data either from the local SQLite database or from a web service. So it is further divided into various components.</p><ul><li><strong>Repository —</strong> It is responsible for handling the data information that includes where to get the data from either a web service or the persisted data models.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68ce9e872443d5af6c171c03f2abf93e/href">https://medium.com/media/68ce9e872443d5af6c171c03f2abf93e/href</a></iframe><ul><li><strong>Room </strong>— It is an ORM provided by Google, which provides an abstraction layer between the SQLite database and our data in the form of objects. It gives us errors in compile-time, which is much better than run-time error which difficult to track and debug. <br>In order to use the room, it’s very important to define our schema. We do that by creating a data model class and add an <a href="http://twitter.com/entity">@entity</a> annotation. We also must add a <a href="http://twitter.com/PrimaryKey">@PrimaryKey</a> annotation to our entity’s id.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de3b88c0331f5a00154c65cffdfb8cdd/href">https://medium.com/media/de3b88c0331f5a00154c65cffdfb8cdd/href</a></iframe><p>After that, we must create our database class extending RoomDatabase, and we must define it as abstract so that room can take care of its implementations.</p><pre>@Database(entities = Movie.class, version = 1)<br>public abstract class MovieDatabase extends RoomDatabase {<br>    private static MovieDatabase <em>instance</em>;<br><br>    public abstract MovieDao movieDao();<br><br>    public static synchronized MovieDatabase getInstance(Context context) {<br>        if (<em>instance </em>== null) {<br>            <em>instance </em>= Room.<em>databaseBuilder</em>(<br>                context.getApplicationContext(), <br>                MovieDatabase.class, &quot;movie_database&quot;<br>            ).fallbackToDestructiveMigration()<br>             .build();<br>        }<br>        return <em>instance</em>;<br>    }<br>}</pre><p>Finally, define all the necessary operation we require from the database. For that, we create an interface to access database, also known as “data access object (DAO)”.</p><pre>@Dao<br>public interface MovieDao {<br>    @Insert<br>    void insert(Movie movie);<br><br>    @Query(&quot;SELECT * FROM favorites&quot;)<br>    public LiveData&lt;List&lt;Movie&gt;&gt; getFavMovies();<br><br>    @Query(&quot;SELECT * FROM favorites WHERE id=:movieId&quot;)<br>    public LiveData&lt;List&lt;Movie&gt;&gt; getCurrentMovie(int movieId);<br><br>    @Delete<br>    void delete(Movie movie);<br>}</pre><ul><li><strong>Web Service — </strong>Now if we wish to access data from a REST API, we have a library called “Retrofit” at our disposal. And it helps us make our network calls. In short, it feeds us the JSON string; we convert that JSON response to java object and add as an entity to our app.</li></ul><h3>Conclusion</h3><p>One an easily make android apps without following this architecture, but if we want to make apps that are robust, testable, maintainable and easy to read, then we must use this to our advantage. I will be writing more on MVVM architecture and how to follow the best practices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa66f7e1a70b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/understanding-mvvm-architecture-in-android-aa66f7e1a70b">Understanding MVVM Architecture  in Android</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vector Assets: Powerful way to create icons and menu items in Android]]></title>
            <link>https://levelup.gitconnected.com/vector-assets-powerful-way-to-create-icons-and-menu-items-in-android-c28b469a7c9b?source=rss-7f15b3f07bd8------2</link>
            <guid isPermaLink="false">https://medium.com/p/c28b469a7c9b</guid>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[vector]]></category>
            <category><![CDATA[assets]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[drawables]]></category>
            <dc:creator><![CDATA[Priyank Kumar]]></dc:creator>
            <pubDate>Mon, 06 Apr 2020 02:58:54 GMT</pubDate>
            <atom:updated>2020-04-25T21:59:23.356Z</atom:updated>
            <content:encoded><![CDATA[<p>Icons and menu items are present in almost all android applications. The most efficient way to go about doing it is using vector assets. It is because android comes in all kinds of devices (phone, tablet, or wearable) and different screen sizes with varying screen densities. And in android, most assets are in bitmap format like images which have an intrinsic scope, which makes our asset look different in same size devices with varying screen density. Now, one can resolve this issue by using the different version on the same asset for varying density. On the other hand, just by using vector format, you only have to do it once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ay7XoW0MiRM1BjjVYtkPiA.png" /></figure><p>Following are the significant benefits of using android vector assets:</p><ol><li><strong>Sharper image </strong>— Since they are assigned with programmatically defined sizes, the icons are sharp on different screen sizes.</li><li><strong>Smaller size </strong>— Vector assets are textual, which makes them easily compressible. Also, we need only one version rather than multiple versions per screen size, which helps us to make our app smaller.</li><li><strong>Animatable </strong>— Because vector assets describe the asset instead of holding the actual image, it opens opportunities to do multiple things like adding animation or make changes dynamically on runtime.</li></ol><h3>How do we make vector assets?</h3><p>When it comes to scalable image, SVG (Scalable Vector Graphics) is the standard around the web, and it uses arbitrary JavaScript to add animation. But SVGs are not appropriate for constrained mobile devices. But android does support SVG’s path specification in form of vector drawable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9202ab3f9c261d51d3916b57b23b117/href">https://medium.com/media/f9202ab3f9c261d51d3916b57b23b117/href</a></iframe><p>It’s written within vector tags with attributes such as:</p><ul><li><strong>android:width</strong> — Intrinsic width.</li><li><strong>android:height</strong> — Intrinsic height.</li><li><strong>android:viewportWidth </strong>— Canvas width</li><li><strong>android:viewportHeight </strong>— Canvas height</li></ul><p>Generally, width and height, and viewportWidth and viewportHeight have the same aspect ratio. The vector can have one or more <strong>path</strong> element within it, and pathData it the attribute responsible for drawing out the path. Let take a look at how that works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKrXHRUdix4WNnQNFtuGdQ.gif" /><figcaption>android:pathData</figcaption></figure><p>It’s very much like PC Logo; you can control movement and actions with different commands. Here “M” before a point in the canvas stands for “move.” and, “L” stands for draw a line. These are the following list other commands you can use to draw virtually any shape:</p><ul><li><strong>M</strong>ove to</li><li><strong>L</strong>ine to</li><li><strong>C</strong>urve to</li><li><strong>A</strong>rc to</li><li><strong>Z</strong> close</li></ul><p>In the path element, we have other attributes like strokeColor, which defines the boundary color and fillColor, which defines the fill color. (Note. we can also add android:alpha property which takes a value between 0–1 to change the opacity of the color.)</p><pre>&lt;vector ... /&gt;<br>    &lt;path .../&gt;<br>    &lt;group<br>        android:name=&quot;egg&quot;<br>        android:pivotX=&quot;8&quot;<br>        android:pivotY=&quot;0&quot;<br>        android:rotation=&quot;180&quot;<br>        android:scaleX=&quot;1&quot;<br>        android:translateY=&quot;-5&quot; /&gt;<br>        &lt;path .../&gt;<br>    &lt;/group&gt;<br>&lt;/vector&gt;</pre><p>Vector drawable also support different transformation between the group of paths. Transformations like rotate, scale translate, which is very similar to CSS. Here pivotX and pivotY are similar to CSS’s transform-origin properties which define the origin point for which animation occurs. Rotate attribute is used to rotate the icon by the degree given by the user. The scale is used to change the size of the icon, and translate used to move the icon with respect to the current position. These are beneficial when it comes to animations but not so useful for static icons.</p><p>Here we can also use clip-path, which masks the area to be displayed. But it does not support anti-aliasing, and that’s why it is not recommended being used liberally.</p><p>How can we actually use vectors in our application? Now, vector drawable is added in SDK version 21 (Lollipop). We use it through VectorDrawable class for a static version and AnimatedVectorDrawable for the animated version. But they were backported as well to the jetpack library so, VectorDrawableCompat and AnimatedVectorDrawableCompat are also available. It is recommended to use VectorDrawableCompat because it allows android to back-port newer features added to later versions and ship new bug fixes.</p><h3>How to use vector assets?</h3><p>To use this at our application we can use ImageView with attribute srcCompat or TextView with drawableCompat attribute, e.g.</p><pre>&lt;!-- With ImageView --&gt;<br>&lt;ImageView<br>    app:srcCompat=&quot;@drawable/my_vector&quot; /&gt;</pre><pre>&lt;!-- With TextView --&gt;</pre><pre>&lt;TextView<br>    app:drawableLeftCompat=&quot;@drawable/my_vector&quot;<br>    app:drawableTint=&quot;@colot/vector_tint&quot;<br>    app:drawableTintMode=&quot;src_in&quot; /&gt;</pre><p>Or, to use this in java code,</p><pre>Drawable d = AppCompatResources.getDrawable(context,<br>       R.drawable.my_vector)</pre><h3>How vector asset loads to our application?</h3><p>Vector asset loads in our app in two steps, firstly the XML file we wrote gets compiled to binary representation and inflate the model object. Secondly perform canvas operation actually to draw those binary data, which may take time. But for static vector assets we can actually cache the result to bitmap to avoid subsequent draws. But we can’t do the same with animated vectors. Which is a slight drawback in compared to bitmaps in which android only have to decode and draw.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubNtdE73_AvOl3yEL3tNuQ.png" /></figure><h3>Looking for more?</h3><p>I will be adding further content on vector assets to do with the conversion process, path morphing and more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c28b469a7c9b" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/vector-assets-powerful-way-to-create-icons-and-menu-items-in-android-c28b469a7c9b">Vector Assets: Powerful way to create icons and menu items in Android</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Consuming REST API in android using Retrofit and GSON.]]></title>
            <link>https://medium.com/@pypriyank/consuming-rest-api-in-android-using-retrofit-and-gson-20268aadf0eb?source=rss-7f15b3f07bd8------2</link>
            <guid isPermaLink="false">https://medium.com/p/20268aadf0eb</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[songs]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[retrofit]]></category>
            <dc:creator><![CDATA[Priyank Kumar]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 03:38:37 GMT</pubDate>
            <atom:updated>2020-03-28T03:38:37.142Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are looking for converting the data, you got from a REST API to a callable object. Then Retrofit is a great type-safe HTTP client for Android and Java. I will be using a JSON response to show how you can use Retrofit in your Android project.<br>In my example, I will be using TMDb’s API to get the latest movies, and we will be displaying that movie list in our app. If you want to follow along, you will need an API key from thetmdb.org, from which you will need to create an account.<br>Let’s go through with the data we are dealing with. So, if I make a get request with:</p><blockquote><a href="https://api.themoviedb.org/3/discover/movie?22&amp;api_key=8a026a6164781758d7295d0a434718dc">https://api.themoviedb.org/3/discover/movie?22&amp;api_key=&lt;</a>YOUR-API-KEY&gt;</blockquote><p>Following will be the JSON data we are going to receive.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb11e61f42610469766249e8306c4e86/href">https://medium.com/media/eb11e61f42610469766249e8306c4e86/href</a></iframe><p>Now let’s get into our android project. The First thing we are going to do is add retrofit and GSON library to our build.gradle (Module:app) &gt; dependencies. <br>Add the following to the dependencies block:</p><pre>implementation &#39;com.squareup.retrofit2:retrofit:2.8.0&#39;<br>implementation &#39;com.squareup.retrofit2:converter-gson:2.8.0&#39;</pre><p>Then we will make a class for each movie object which looks like it’s is inside an array with the key of “results”. So first we will make a class for the entire response.</p><pre>public class TMDB_Response {<br><br>    @SerializedName(&quot;results&quot;)<br>    @Expose<br>    private ArrayList&lt;Movie&gt; results;<br><br>    public ArrayList&lt;Movie&gt; getResults() {<br>        return results;<br>    }<br><br>    @NonNull<br>    @Override<br>    public String toString() {<br>        return results.toString();<br>    }<br>}</pre><p>Now we will make a class for each movies.</p><pre>public class Movie {<br><br>    @SerializedName(&quot;id&quot;)<br>    @Expose<br>    private String id;<br>    @SerializedName(&quot;title&quot;)<br>    @Expose<br>    private String title;<br>    @SerializedName(&quot;poster_path&quot;)<br>    @Expose<br>    private String imagePath;<br>    @SerializedName(&quot;release_date&quot;)<br>    @Expose<br>    private String releaseDate;<br>    @SerializedName(&quot;overview&quot;)<br>    @Expose<br>    private String overview;<br>    @SerializedName(&quot;vote_average&quot;)<br>    @Expose<br>    private String voteAverage;<br><br><br><br>    public String getId() {<br>        return id;<br>    }<br>    public String getTitle() {<br>        return title;<br>    }<br><br>    public String getImagePath() {<br>        return imagePath;<br>    }<br><br>    public String getReleaseDate() {<br>        return releaseDate;<br>    }<br><br>    public String getOverview() {<br>        return overview;<br>    }<br><br>    public String getVoteAverage() {<br>        return voteAverage;<br>    }<br>}</pre><p>In the codes above we have use annotation “SerializedName” to get the value for the passed string, and assign it to the instance variable.</p><p>Before getting to our main activity class, it would be a good practice if we use a RecyclerView to display the list of movies.</p><pre>public class MyMovieRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyMovieRecyclerViewAdapter.MyMovieViewHolder&gt; {<br><br>    private Context mContext;<br>    private ArrayList&lt;Movie&gt; mMovieList;<br><br>    public MyMovieRecyclerViewAdapter(Context context, ArrayList&lt;Movie&gt; movieArrayList) {<br>        mContext = context;<br>        mMovieList = movieArrayList;<br>    }<br><br>    private static String <em>IMAGE_BASE_URL </em>= &quot;https://image.tmdb.org/t/p/w185&quot;;<br><br>    @NonNull<br>    @Override<br>    public MyMovieViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {<br>        View v = LayoutInflater.<em>from</em>(mContext).inflate(R.layout.<em>fragment_movie</em>, parent, false);<br>        return new MyMovieViewHolder(v);<br>    }<br><br>    @Override<br>    public void onBindViewHolder(@NonNull MyMovieViewHolder holder, int position) {<br>        Movie currentMovie = mMovieList.get(position);<br><br>        String movieImagePath = <em>IMAGE_BASE_URL </em>+ currentMovie.getImagePath();<br>        String movieTitle = currentMovie.getTitle();<br><br>        holder.mMovieTitle.setText(movieTitle);<br>        Log.<em>v</em>(&quot;imagepath&quot;, movieImagePath);<br><br>        Picasso.<em>get</em>()<br>                .load(movieImagePath)<br>                .fit()<br>                .centerInside()<br>                .into(holder.mMovieImage);<br>    }<br><br>    @Override<br>    public int getItemCount() {<br>        return mMovieList.size();<br>    }<br><br>    public class MyMovieViewHolder extends RecyclerView.ViewHolder {<br><br>        public ImageView mMovieImage;<br>        public TextView mMovieTitle;<br>        public MyMovieViewHolder(@NonNull View itemView) {<br>            super(itemView);<br><br>            mMovieImage = itemView.findViewById(R.id.<em>movie_image</em>);<br>            mMovieTitle = itemView.findViewById(R.id.<em>movie_title</em>);<br>        }<br>    }<br>}</pre><p>We are all done now, Only thing left is to perform the network call and get our formatted list of movies. So in our MainActivity we do following:</p><pre>private static final TMDB_KEY = &lt;YOUR API KEY GOES HERE&gt;<br>private RecyclerView mRecyclerView;<br>private MyMovieRecyclerViewAdapter mMyMovieAdapter;<br>private ArrayList&lt;Movie&gt; mMovieList;<br><br>@Override<br>protected void onCreate(Bundle savedInstanceState) {<br>    super.onCreate(savedInstanceState);<br>    setContentView(R.layout.<em>activity_main</em>);<br><br>    Retrofit retrofit = new Retrofit.Builder()<br>            .baseUrl(<em>BASE_URL</em>)<br>            .addConverterFactory(GsonConverterFactory.<em>create</em>())<br>            .build();<br>    MovieDatabaseAPI movieDatabaseAPI = retrofit.create(MovieDatabaseAPI.class);<br>    Call&lt;TMDB_Response&gt; call = movieDatabaseAPI.getMovies(<em>TMDB_KEY</em>);<br><br>    mRecyclerView = findViewById(R.id.<em>movie_recycler_view</em>);<br>    mRecyclerView.setHasFixedSize(true);<br>    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));<br><br><br>    call.enqueue(new Callback&lt;TMDB_Response&gt;() {<br>        @Override<br>        public void onResponse(Call&lt;TMDB_Response&gt; call, Response&lt;TMDB_Response&gt; response) {<br>            if(!response.isSuccessful()) {<br>                Toast.<em>makeText</em>(getApplicationContext(), response.code(), Toast.<em>LENGTH_SHORT</em>).show();<br>                return;<br>            }<br><br>            TMDB_Response tmdb_response = response.body();<br>            assert tmdb_response != null;<br>            mMovieList = tmdb_response.getResults();<br><br>            mMyMovieAdapter = new MyMovieRecyclerViewAdapter(MainActivity.this, mMovieList);<br>            mRecyclerView.setAdapter(mMyMovieAdapter);<br>        }<br><br>        @Override<br>        public void onFailure(Call&lt;TMDB_Response&gt; call, Throwable t) {<br>            Toast.<em>makeText</em>(getApplicationContext(), t.getMessage(), Toast.<em>LENGTH_SHORT</em>).show();<br>        }<br>    });<br>}</pre><p>That will be it, make sure your layout is correctly done, you will be getting the list of movies with thumbnail.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20268aadf0eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>