title: How to unsubscribe from the rxJava request
body: <p>I have the following class, I want to return Subscription object or something else so I can cancel the request from where I have referenced subscribe() method , but subscribe(observer) returns void!
  How can I do that?</p>
  
  <pre><code>public abstract class MainPresenter&lt;T&gt; {
  protected &lt;T&gt; Disposable subscribe(Observable&lt;T&gt; observable, Observer&lt;T&gt; observer) {
  observable.subscribeOn(Schedulers.newThread())
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe(observer);
  
  }
  </code></pre>
  
  <p>[<em>New Update</em>]
  I used this way temporary, I am waiting for better solutions:</p>
  
  <pre><code>    protected &lt;T&gt; DisposableMaybeObserver subscribe(final Maybe&lt;T&gt; observable,
                                                  final Observer&lt;T&gt; observer) {
      return observable.subscribeOn(Schedulers.io())
              .observeOn(AndroidSchedulers.mainThread())
              .subscribeWith(new DisposableMaybeObserver&lt;T&gt;() {
                  @Override
                  public void onSuccess(T t) {
                      observer.onNext(t);
                  }
  
                  @Override
                  public void onError(Throwable e) {
                      observer.onError(e);
                  }
  
                  @Override
                  public void onComplete() {
                      observer.onComplete();
                  }
              });
  }
  </code></pre>
  
  <p>[<em>New Update 2</em>]
  [![Screenshot][<a href="https://i.stack.imgur.com/mioth.jpg]]" rel="nofollow noreferrer">https://i.stack.imgur.com/mioth.jpg]]</a></p>
  
  <p>[<em>New Update 3</em>]
  [<img src="https://i.stack.imgur.com/8XnLB.jpg" alt="Screenshot2">]<a href="https://i.stack.imgur.com/8XnLB.jpg" rel="nofollow noreferrer">1</a></p>