title: Waiting for ASyncTask to finish or variable to be set
body: <p>I am trying to set a variable in an activity to the result of my AsyncTask. I have read that I cannot return a variable and that I would have to set up the variable in my activity and then change it in the <code>onPostExecute</code> method.</p>
  
  <p>My problem is that after the AsyncTask finishes I need to use that variable. I am having trouble with this because all the solutions I have tried so far cause the UI to freeze up and then go non-responding.</p>
  
  <p>What I have tried so far:</p>
  
  <pre><code>while (!task.isCancelled()) {
      // Wait... 
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>while (variable == null) { 
      // Wait ...
  }
  </code></pre>
  
  <p>Is what I am doing the best way to pass a variable from the AsyncTask to my Activity? If it is then how can I wait for the task to finish in the activity without locking up the UI?</p>