Show result of long task after a ProgressDialog
<p><br>
I have an application which runs a long task and returns a value. While the task is running, a <code>ProgressDialog</code> shows the progress. After the task is done I want to show the result in a <code>TextView</code>. I run the task in a FutureTask.<br>
My problem is that if I try to get the result, the <code>.get()</code> method of FutureTask blocks the UI Thread and I don't see the <code>ProgressDialog</code> (the <code>TextView</code> displays the result propertly).  </p>

<p>My code for the task (pool is ExecutorService):  </p>

<pre><code>final FutureTask&lt;String&gt; future = new FutureTask&lt;String&gt;(new Callable&lt;String&gt;() {  
    @Override  
    public String call() {  
        return myLongTask();  
    }  
});  
pool.execute(future);
</code></pre>

<p>And afterwards I call <code>updateProgressBar()</code> in a <code>Runnable</code> which updates the <code>ProgressDialog</code> with a <code>Handler</code>:  </p>

<pre><code>Runnable pb = new Runnable() {  
    public void run() {  
        myUpdateProgressBar();  
    }  
};  
pool.execute(pb);
</code></pre>

<p>Now I'm getting the result, which blocks the UI Thread preventing the <code>ProgressDialog</code> to show up:  </p>

<pre><code>String result = future.get()
</code></pre>

<p>If I try to put the result inside the updateProgressBar() method (by passing the future as a parameter) after the ProgressDialog dismisses, an Exception is thrown:  </p>

<blockquote>
  <p>Only the original thread that created a view hierarchy can touch its views.</p>
</blockquote>

<p>Any ideas how to solve this problem? (I've heard about AsyncTasks but I can't figure out how to use them propertly.)</p>
