title: Unsubscribing from RxJava2/RxAndroid PublishSubject
body: <p>I'm trying to replace EventBus with RxAndroid. </p>
  
  <p>I want pageable fragments to subscribe/unsubscribe to an event source, these fragments get created and discarded relatively quickly, depending on how fast the user slides to a new page.</p>
  
  <p>In EventBus I was able to add an decorated callback method (ie <code>@Subscribe(threadMode = ThreadMode.MAIN)</code>) and register/unregister in the onStart/onStop methods of the fragment.</p>
  
  <p>With RxJava2 I now create a <code>PublishSubject</code> object in a class</p>
  
  <pre><code>public static PublishSubject&lt;List&lt;Long&gt;&gt; m_psUpdatedDays = PublishSubject.create();
  public static void publishUpdatedDays(List&lt;Long&gt; lDay) {
      m_psUpdatedDays.onNext(lDay);
  }
  </code></pre>
  
  <p>and subscribe to this publisher in another class by calling the following in the Fragment's <code>onStart</code> method:</p>
  
  <pre><code>m_psUpdatedDays.observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer&lt;List&lt;Long&gt;&gt;() {
      @Override public void onSubscribe(Disposable d) {}
      @Override public void onNext(List&lt;Long&gt; longs) {
        ...
        Update Fragment UI here
        ...
      }
      @Override public void onError(Throwable e) {}
      @Override public void onComplete() {}
  });
  </code></pre>
  
  <p>My question is how can I unsubscribe this new Observer when the Fragment's <code>onStop</code> method is called by the system?</p>
  
  <p>Do I need to store the <code>Disposable</code> object which I get in the <code>onSubscribe</code> and then call <code>.dispose()</code> on it in the <code>onStop</code> method?</p>