title: Emit single item while update UI about progress in RxJava / RxAndroid
body: <p>I'm currently trying to learn RxJava in Android. I require some guides.
  At the moment, I'm trying to rewrite AsyncTask below to RxJava:</p>
  
  <pre><code>public class MyAsyncTask extends AsyncTask&lt;Void, ProgressInfo, Result&gt; {
      @Override
      protected Result doInBackground(Void... void) {
          //Long running task
          publishProgress(progressInfo);
          //Long running task
          return result;
      }
      @Override
      protected void onProgressUpdate(ProgressInfo... progressInfo) {
          //Update the progress to UI using data from ProgressInfo
      }
      @Override
      protected void onPostExecute(Result res) {
          //Task is completed with a Result
      }
  }
  </code></pre>
  
  <p>In AsyncTask approach shown above, I can update the UI about the progress by making use of <code>onProgressUpdate</code> method, I pack every data I needed into <code>ProgressInfo</code> and reflect the UI in <code>onProgressUpdate</code>. After task ends, the <code>Result</code> will be passed from from <code>doInBackground</code> to <code>onPostExecute</code>.</p>
  
  <p>But, when I'm trying to implement this with RxJava, I have a hard time dealing with it. Since I cannot pass any parameter to <code>onComplete</code> in Observer. And thus, I ended up with following implementation. I merged the pass of the <code>ProgressInfo</code> and <code>Result</code> into <code>onNext</code>.</p>
  
  <pre><code> Observable.create(emitter -&gt; {
                  //Long running task
                  emitter.onNext(progressInfo);
                  //Long running task
                  emitter.onNext(result);
              }).subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(object -&gt; {
                      if(object instanceof ProgressInfo){
                          //Update the progress to UI using data from ProgressInfo
                      }else if(object instanceof Result){
                          //Task is completed with a Result
                      }
                  });
  </code></pre>
  
  <p><strong>QUESTION 1: Is my implementation/concept in RxJava right or wrong?</strong></p>
  
  <p>Although it works, I personally feels the implementation above strange and wrong to me. Since the task ultimately is just trying to do some calculations and come out with a single item - <code>Result</code>. The emission of <code>ProgressInfo</code> is like a "side" thing but not "main" thing. I should implement it with Single.create(). But if I did this, I cannot think of any way to pass any <code>ProgressInfo</code> to my UI.  </p>
  
  <p><strong>QUESTION 2:
  Is there a better idea/way to emit single item while updating the UI during the process?</strong></p>
  
  <p>If yes, how would you implement this logic in RxJava? Can you show me your codes/examples?</p>