I wouldn't trust that not to have a deadlock. Not to mention sitting in a tight loop polling is pretty wretched.
If the desire is: "I want to execute whatever is the most recent operation, dropping any before it," then my general solution is to have a pointer to the most recent operation, schedule the work for it when first setting it, and when that work is done checking to see if there is another operation to execute and starting again if so. That way as you create new operations while the first one is running, you just drop any that haven't started yet. And when the last one that was started running is done it will start execution of whatever was the last thing you wanted to happen. On Sat, Sep 10, 2011 at 7:13 AM, bob <[email protected]> wrote: > That's a possibility. Or, I might use this function I wrote: > > void replaceCurrentTask(android.os.AsyncTask<Void, Void, Long> > newTask){ > if (currentTask != null) { > > currentTask.cancel(true); > while (!currentTask.isCancelled() && > currentTask.getStatus()! > =AsyncTask.Status.FINISHED) trytosleep(1); > } > > currentTask=newTask; > currentTask.execute(); > > } > > > > On Sep 10, 4:36 am, Marco Alexander Schmitz > <[email protected]> wrote: > > Hi. How about blocking the ui with some nice waiting dialog? Greetings > marco > > Am 10.09.2011 09:39 schrieb "bob" <[email protected]>: > > > > > > > > > > > > > > > > > So, I have a bunch of buttons and each one launches an AsyncTask. > > > > > So, should I keep a variable like this: > > > > > AsyncTask currentTask=null; > > > > > Then should I do > > > > > if (currentTask != null) currentTask.cancel(); > > > > > before I launch the new task? > > > > > I only want one task running at a time. Right now, if someone monkeys > > > with the buttons, they get a bunch of tasks running simultaneously > > > with weird UI results. > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Developers" group. > > > To post to this group, send email to > [email protected] > > > To unsubscribe from this group, send email to > > > [email protected] > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

