Android RxJava Observable.interval() doesn't stop emitting items
<p>I have a static field </p>

<pre><code> private static Subscription timer;
</code></pre>

<p>and two static methods:</p>

<pre><code>public static void setTimer() {
    timer = Observable.interval(2, TimeUnit.SECONDS, Schedulers.computation())
            .doOnNext(tick -&gt; update(tick))
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe();
}

public static void removeTimer() {
    if (timer != null &amp;&amp; !timer.isUnsubscribed()) {
        timer.unsubscribe();
        timer = null;
    }
}
</code></pre>

<p>Guessing after unsubsription Observable have to stop emitting items.
However it doesn't work. If function updatePrices is</p>

<pre><code>private static void update(long tick) {
    Log.d(TAG, "tick");
}
</code></pre>

<p>Logs continue to be printed after calling removeTimer().</p>

<p>So the question is how to stop emitting items in my observable correctly?</p>

<h1>Solved</h1>

<p>The issue was in double calling of setTimer().</p>

<p>However I still have a question. Can anybody explain why is the old copy of timer still continues to emit items after the second call of setTimer()?</p>