The situation is very simple. I use an AsyncTask to retrieve a String from an HttpClient.
Now I need the String retrieved by the AsyncTask to call another method on that String,
therefore i need to make sure the AsyncTask has terminated before calling the other method.
How do I do this?
Thanks for any suggestion.
Use a simple lock or mutex. Basically, add a variable and a getter in your AsyncTask:
public boolean locked;
public boolean isLocked(){
return locked;
}
in your AsyncTask's onPreExecute method, add:
locked = true;
and in the onPostExecute method, add:
locked = false;
Any outside methods can then be placed into a loop such as:
MyTask foo = new MyTask();
foo.execute();
while (foo.isLocked())
{
//wait, or sleep, or whatever
}
//here is where you execute code.
Just check if onPostExecute() already was called
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With