<?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 Titto Jose on Medium]]></title>
        <description><![CDATA[Stories by Titto Jose on Medium]]></description>
        <link>https://medium.com/@tittojose?source=rss-32e9cbf6915d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uSuKxsAwL4N-pFP2fqsvpA.jpeg</url>
            <title>Stories by Titto Jose on Medium</title>
            <link>https://medium.com/@tittojose?source=rss-32e9cbf6915d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 19:05:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tittojose/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[Migrate API calls from RxJava to Kotlin Coroutines]]></title>
            <link>https://tittojose.medium.com/migrate-api-calls-from-rxjava-to-kotlin-coroutines-dadb6e5d0f8?source=rss-32e9cbf6915d------2</link>
            <guid isPermaLink="false">https://medium.com/p/dadb6e5d0f8</guid>
            <category><![CDATA[retrofit]]></category>
            <category><![CDATA[coroutine]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Titto Jose]]></dc:creator>
            <pubDate>Sun, 24 Jan 2021 16:19:48 GMT</pubDate>
            <atom:updated>2021-01-24T16:19:48.518Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro</h3><p>This example describes how to migrate from RxJava for making asynchronous API calls to Kotlin Coroutine.</p><p>To understand the migration, Let&#39;s take an example of a simple weather app that makes an HTTP request to weather API and display current weather information. The project will be based on the MVP architecture and will be using Retrofit to make API calls.</p><p>Link to the Repo :</p><p><a href="https://github.com/tittojose/weatherapp-coroutine-migration">tittojose/weatherapp-coroutine-migration</a></p><p>Let’s get started!</p><h3><strong>Project Structure</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*VTQu33Dyg73leOWQkUTJqQ.png" /></figure><p>▹ <strong>model </strong>package<strong>:</strong></p><ul><li><strong><em>WeatherAPI</em></strong><em> - </em>consists of API contracts.</li><li><strong>APIClient</strong> - Retrofit service provider.</li><li><strong>pojo</strong> package - Kotlin data classes for containing weather information.</li></ul><p>▹ <strong>presenter </strong>package<strong>:</strong></p><ul><li><strong>HomeScreenPresenter</strong> -<em> Presenter class for all the presentation logic.</em></li></ul><p>▹ <strong>view </strong>package<strong>:</strong></p><ul><li><strong>HomeScreen </strong>-<em> view contract</em></li><li><strong>HomeScreenActivity </strong>- Activity class to display the current weather.</li></ul><p><em>Let&#39;s look at the changes required for migration.</em></p><h3>Dependencies</h3><p><strong>RxJava</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd9d9b64dd74faee5eaa6ccf068b6ccc/href">https://medium.com/media/cd9d9b64dd74faee5eaa6ccf068b6ccc/href</a></iframe><p><strong>Coroutine</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/558eaa8e48ab7d1c9612731033c3fe96/href">https://medium.com/media/558eaa8e48ab7d1c9612731033c3fe96/href</a></iframe><h3><strong>Network Layer: APIClient</strong></h3><p><strong>RxJava</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a8243e2033accbdaaa68d69f1807b51/href">https://medium.com/media/0a8243e2033accbdaaa68d69f1807b51/href</a></iframe><p><strong>Coroutine</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69b7ea8402214e9d84eaf695e433e251/href">https://medium.com/media/69b7ea8402214e9d84eaf695e433e251/href</a></iframe><blockquote>Deleted the unwanted RxJava adapter for converting API call responses to Rx streams.</blockquote><blockquote>Retrofit added support for coroutine from version — 2.6.0</blockquote><h3>Network Layer: WeatherAPI</h3><p><strong>RxJava</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f712ac167738a77d84f8feb86d93584/href">https://medium.com/media/5f712ac167738a77d84f8feb86d93584/href</a></iframe><p><strong>Coroutine</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6378ee326fca4b8fcdd2eda02c167af0/href">https://medium.com/media/6378ee326fca4b8fcdd2eda02c167af0/href</a></iframe><blockquote>function <strong>getCurrentWeather</strong> is refactored to type <strong>suspend</strong> function and return type <strong>Single&lt;WeatherModel&gt;</strong> to <strong>WeatherModel</strong></blockquote><h3>Presentation Layer: WeatherAPI</h3><p><strong>RxJava</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee3784853a192e24ff87157312ea0d24/href">https://medium.com/media/ee3784853a192e24ff87157312ea0d24/href</a></iframe><p><strong>Coroutine</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf9b3d4b9abc9ea4809c116d7b004de6/href">https://medium.com/media/cf9b3d4b9abc9ea4809c116d7b004de6/href</a></iframe><blockquote><strong>loadWeatherData() </strong>function invokes the coroutine. <strong>CoroutineScopes</strong> are used to switch between the <strong>Main thread and IO thread</strong>. <strong>Dispatchers.IO</strong> is used to execute the <em>async</em> HTTP request on the Worker thread (non-main thread).</blockquote><blockquote>View rendering is executed on the <strong>Main thread</strong> using the <strong>Dispatchers.Main</strong> scope.</blockquote><blockquote><strong>Errors</strong> are handled using the try catch block around the coroutine invokaction</blockquote><blockquote>The function execution has to be <strong>cancelled</strong> explicitly by <strong>job.cancel</strong> when <strong>presenter.onDestroy</strong> is called when the view is destroyed.</blockquote><h3><strong>View Layer : HomeScreenActivity</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af51c9dc91ff316bd161189e5d217885/href">https://medium.com/media/af51c9dc91ff316bd161189e5d217885/href</a></iframe><blockquote>There is absolutely no changes required in the <strong>view</strong> classes.</blockquote><h3>Finally</h3><p>We have successfully migrated our weather app to use Coroutines replacing RxJava. In effect, we’ve made the code simple, more readable, and straightforward.</p><p>Read more about Coroutines here:</p><ul><li><a href="https://proandroiddev.com/suspend-what-youre-doing-retrofit-has-now-coroutines-support-c65bd09ba067">Suspend what you’re doing: Retrofit has now Coroutines support!</a></li><li><a href="https://blog.mindorks.com/using-retrofit-with-kotlin-coroutines-in-android">Using Retrofit with Kotlin Coroutines in Android</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dadb6e5d0f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>