title: How to access result of void onComplete() of a Task
body: <p>I'm working with a lib strangely designed this code basically has a <code>Task</code> object with<code>onComplete()</code> and <code>onfail()</code> methods, both these methods are void so I cannot use return inside them.</p>
  
  <p>I have tried to use an external variable updated inside the task <code>onComplete()</code> and <code>onfail()</code>using  </p>
  
  <pre><code>mytask.wait();
  return value; 
  </code></pre>
  
  <p>with the intention to wait for the completion of the task and then return value but I get</p>
  
  <pre><code>java.lang.IllegalMonitorStateException: object not locked by thread before wait()
  </code></pre>
  
  <p>if I try something like</p>
  
  <pre><code>while(!mytask.isComplete(){}
  </code></pre>
  
  <p>to force the method to wait the completion</p>
  
  <p>app totally freezes </p>
  
  <p>How could I get the value at the completion of the task correctly?</p>