<?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 Peter Staranchuk on Medium]]></title>
        <description><![CDATA[Stories by Peter Staranchuk on Medium]]></description>
        <link>https://medium.com/@peterstaranchuk?source=rss-44802b63feb7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*CmvYbPEeA5lTo1nLiXajrA.jpeg</url>
            <title>Stories by Peter Staranchuk on Medium</title>
            <link>https://medium.com/@peterstaranchuk?source=rss-44802b63feb7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:13:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@peterstaranchuk/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[Important notices about the behavior of observeOn and subscribeOn in RxJava2]]></title>
            <link>https://medium.com/@peterstaranchuk/important-behaviour-of-observeon-and-subscribeon-in-rxjava2-c46f80e261d3?source=rss-44802b63feb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c46f80e261d3</guid>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[rxjava2]]></category>
            <dc:creator><![CDATA[Peter Staranchuk]]></dc:creator>
            <pubDate>Sun, 15 Sep 2019 11:07:18 GMT</pubDate>
            <atom:updated>2019-09-15T17:23:38.599Z</atom:updated>
            <content:encoded><![CDATA[<p>Is this article about RxJava in 2019? We use this framework so often what we have to know all about it by this time, but I see a lot of questions/bugs on StackOverflow and in chats about Android development related to the behavior of these operators and how they affect chain. So this article will be most useful for Junior and Middle Android developers and developers who want better understand RxJava2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*JU1waus_aeDHn-t3gFmdYA.png" /></figure><h3>1. observeOn and initial Scheduler</h3><p>Let’s see first example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/169c2cf6c85dde4450fc136cbfa29916/href">https://medium.com/media/169c2cf6c85dde4450fc136cbfa29916/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*_czpNYN9rGwymnfgzLWunQ.png" /></figure><p>Initially Observable which we create with Observable.just(…), Observable.create(…) and Observable.fromArray(…) emit items in the thread where it was created. In our case in MainThread. So if you will see code like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/279c08967574ed71b9dc59c44a75d5d6/href">https://medium.com/media/279c08967574ed71b9dc59c44a75d5d6/href</a></iframe><p>You can remove observeOn(AndroidSchedulers.mainThread()) and it will work completely the same.</p><p>Another important thing is when you create Observable from RxJava operator it will run in thread specified by scheduler in this operator definition. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a578cc32113c1139a6a18ab974c8c73/href">https://medium.com/media/3a578cc32113c1139a6a18ab974c8c73/href</a></iframe><p>And we can see scheduler definition inside Observable.interval( ) method declaration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bc5928de3652108ef17ec5cc0c13729/href">https://medium.com/media/7bc5928de3652108ef17ec5cc0c13729/href</a></iframe><p>So. Keep this in mind :)</p><h3>2. subscribeOn</h3><p>subscribeOn change thread in which Observable emit items. Chain will use this thread until it will see first observeOn operator (which will change chain thread. See diagram below).</p><p>Let’s see an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13dc6f80a63b023c6b61dd7d6e8c0015/href">https://medium.com/media/13dc6f80a63b023c6b61dd7d6e8c0015/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*bgP6tZB7D_D6JoKjqveX7A.png" /></figure><p>If you will call subscribeOn more than once RxJava will ignore all subscribeOn after first so code above and below have the same behavior:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf9fdf16b53ca18e691683c78b9bddf2/href">https://medium.com/media/bf9fdf16b53ca18e691683c78b9bddf2/href</a></iframe><p>Hope it was interesting :) subscribe on new articles on my Facebook: <a href="https://www.facebook.com/staranchuk">https://www.facebook.com/staranchuk</a> or LinkedIn: <a href="https://www.linkedin.com/in/peterstaranchuk/">https://www.linkedin.com/in/peterstaranchuk/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c46f80e261d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>