Handling callbacks with RxJava
<p>I am trying to understand what is the best way to handle a particular case, using RxJava.</p>

<p>I need to return an <code>Observable</code> which handles the removal of an account from the Android <code>AccountManager</code>. Unfortunately, this action is asynchronous and it needs a callback to handle the result.</p>

<p>Because of this, I am using the <code>Observable.create</code> method, in this way:</p>

<pre><code>return Observable.create(subscriber -&gt; {
        final Account account = getAccountIfExist();
        if (account == null) {
            subscriber.onError(new NoUserFoundException());
            return;
        }

        accountManager.removeAccount(account, future -&gt; {
            boolean result = false;
            try {
                result = future.getResult();
            } catch (Exception ex) {
                Log.e(TAG, "Remove account not successful : ", ex);
                subscriber.onError(ex);
                return;
            }

            if (result) {
                subscriber.onNext(account.name);
                subscriber.onCompleted();
            } else {
                subscriber.onError(new RuntimeException("Cannot remove the account."));
            }
        }, null);
    });
</code></pre>

<p>But, <code>Observable.create</code> has different problems dealing backpressure and cancellation, as stated in this <a href="https://stackoverflow.com/questions/34204802/creating-observable-without-using-observable-create">post</a></p>

<p>So, the question is, how can I use <code>Observable.fromCallable</code> (or an equivalent method) for handling callbacks (in general) and also dealing with backpressure and cancellation?</p>