Ali Chousein wrote: > Thank you for the reply and the suggestion. Having two threads, one > waiting for the other was the best solution for my problem, but > apparently calling wait() in AsyncTask is not supported. Probably I'll > have multiple AsyncTasks, which don't wait for each other, but which > combine subsets of the functionality of the original A1 and A2 > AsyncTasks.
Or switch out from AsyncTasks to something else. For example, when I think "producer-consumer", I think LinkedBlockingQueue. Of course, LinkedBlockingQueue has always been my favorite of the concurrency classes, so I may tend to overuse it. > Until tonight I used to like the idea of AsyncTask. I don't understand > why the creators of Android cannot make such handy ideas more generic. Particularly when it comes to Java and threading, there is no single solution that fits every pattern. AsyncTask is designed for discrete, short-lived, independent operations. Outside of that, grab relevant classes out of java.util.concurrent, and use Handler or related methods to invoke logic on the main application thread. > @Mr Murphy: BTW, it could be a good idea to extend each chapter of > your Android books with a section of known issues. The books are > great, but they could be better if they also explain the limitations > to an extent. Uh, there aren't enough bytes on my hard drive for that. :-) More seriously, take your circumstance. As far as I'm concerned, the use of wait() by ordinary Java developers has been obsolete for about a decade. Once Doug Lea published his concurrency library -- what you now think of as java.util.concurrent -- no ordinary Java developer should be using low-level blocking protocols like wait(), IMHO. There are plenty of viable patterns already implemented in java.util.concurrent. And Mr. Lea is way smarter than the rest of us when it comes to Java threading. Hence, I would not be advising people in my book to avoid wait() in an AsyncTask, because I would not be advising people to use wait() in the first place. I am certainly interested in concrete suggestions for improving the books -- just head over to the [cw-android] Google Group and chime in. I am not sure how I can do a "known issues" section in every chapter, but I will give it some thought. Thanks for the feedback! -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 3.1 Available! -- 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

