title: RXJava and DialogFragment => Dialog waits for observable - why?
body: <p>I show a <code>DialogFragment</code> and load data in the background. I want the dialog to show up, the data keeps on loading and incrementally updates the already visible dialog. </p>
  
  <p><strong>Problem</strong></p>
  
  <p>The dialog is not shown before the observable completes. Why?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>private final static Handler mHandler = new Handler();
  
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
  
      Observable&lt;List&lt;Data&gt;&gt; observable =  Observable.create(new Observable.OnSubscribe&lt;Data&gt;()
      {
          @Override
          public void call(Subscriber&lt;? super Data&gt; subscriber)
          {
  
              // iterate and create data
              for (int i = resolveInfo.size() - 1; i &gt;= 0; i--)
              {
                   Data d = ...;
                   subscriber.onNext(d);
              }
  
              subscriber.onCompleted();
          }
      })
              .onBackpressureBuffer()
              .buffer(150, TimeUnit.MILLISECONDS)
              .filter(new Func1&lt;List&lt;Data&gt;, Boolean&gt;()
              {
                  @Override
                  public Boolean call(List&lt;Data&gt; rxSingleDatas)
                  {
                      return rxSingleDatas.size() &gt; 0; // only deliver not emtpy lists!
                  }
              })
              .onBackpressureBuffer()
              .doOnNext(new Action1&lt;List&lt;Data&gt;&gt;()
              {
                  @Override
                  public void call(List&lt;Data&gt; shareDatas)
                  {
                      // add result to list + notify adapter
                      for (int i = 0; i &lt; shareDatas.size(); i++)
                          mData.add(shareData);
                      if (mAdapter != null)
                          mAdapter.notifyDataSetChanged();
                  }
              })
              .doOnCompleted(new Action0()
              {
                  @Override
                  public void call()
                  {
                      // flag to indicate all data is loaded
                      mReady = true;
                  }
              });
  
      // subscribe on handler thread for async execution
      // observe on main thread for updating UI
      mSubscription = observable
              .subscribeOn(HandlerScheduler.from(mHandler))
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe();
  }
  
  @Override
  public void onDestroy()
  {
      if (mSubscription != null)
          mSubscription.unsubscribe();
      super.onDestroy();
  }
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState)
  {
      MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity())
              .title(R.string.share_with)
          .cancelable(true)
          .autoDismiss(false);
  
      mAdapter = ...;
      builder
              .adapter(mAdapter, new MaterialDialog.ListCallback() {
                  @Override
                  public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
  
                      if (!mReady)
                          return;
  
                      // handle click
                  }
              });
  
      MaterialDialog dlg = builder.build();
      return dlg;
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I replaced the handler with one that's running on the background thread, but this leads to following execption: <code>CalledFromWrongThreadException</code> when trying to update the adapter in the <code>doOnNext</code> call... I would say the <code>observeOn</code> should have the effect that the <code>doOnNext</code> is called on the main thread, but it seems, that this does not work...</p>