title: RxJava async task in Android
body: <p>I am trying to implement an asynchronous task using RxJava in Android.
  I tried the following code and it didn't work. It executes on the UI thread. I am using the following version of RxAndroid 0.24.0.</p>
  <pre><code>try {
      Observable.just(someMethodWhichThrowsException())
              .subscribeOn(Schedulers.newThread())
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe(s -&gt; onMergeComplete());
  }
  catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  <p>However, the following works asynchronously for me.</p>
  <pre><code>Observable observable = Observable.create(new Observable.OnSubscribe&lt;String&gt;() {
          @Override
          public void call(Subscriber&lt;? super String&gt; subscriber) {
              try {
                  someMethodWhichThrowsException();
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
              subscriber.onCompleted();
          }
      });
      observable.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe();
  </code></pre>
  <p>I am trying to understand the following:</p>
  <ol>
  <li>What is the difference between them?</li>
  <li>What is the best practice while creating async tasks?</li>
  </ol>