title: Stop Observable from loop
body: <p>Recently I have been working on RxJava 2 and I have tested the <strong>Observable.interval()</strong> </p>
  
  <pre><code>subscription = Observable.interval(1, TimeUnit.MILLISECONDS, Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
  
  subscription.subscribe(new Observer&lt;Long&gt;() {
              @Override
              public void onSubscribe(Disposable d) {
  
              }
  
              @Override
              public void onNext(Long aLong) {
                  //binding.appBar.mainContent.msg.setText(aLong+"");
              }
  
              @Override
              public void onError(Throwable e) {
  
              }
  
              @Override
              public void onComplete() {
  
              }
          });
  </code></pre>
  
  <p>Observable is started after activity's <code>onCreate</code> method. And I am logging the output through <code>onNext()</code> method. And I have a Stop Button. When it is triggered I want to stop subscription flow.</p>
  
  <p>Even after the stop button is clicked the log keeps on going. </p>
  
  <pre><code>stop.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (subscription != null) {
                      subscription.unsubscribeOn(Schedulers.io());
                  }
              }
          });
  </code></pre>