Thanks Streets Of Boston and Mike for your replies and ideas. I managed to solve this problem with your help. After some testing i made a Service which executes my tasks. When a task has a result i send the results to the activity which called the function on the service. When the screen rotates i null the activity pointer in the service and on the oncreate i set the activity pointer to the current activity.
If a task finishes with a result while the screen is rotating (ie activity pointer is null) i simply wait a couple seconds and see if the activity pointer is still null. The last step is still a bit crude, i might test a bit with lock/wait/ notify (if that works with services) or queuing results in the service. One problem with this whole setup that a service can only execute 1 task from 1 activity at a time. Cheers, Twan On Jun 3, 11:16 am, Mike Hearn <[email protected]> wrote: > If you look at Romain Guys Shelves app (where this class originates) > he actually stops then restarts asynctasks when the screen rotates. > > This doesn't seem like a great way to go, as you throw away the > progress. But as AsyncTasks have a reference to the activity, I can > see why it's done. The whole configuration change means destruction > thing has a lot of nasty side effects. I sometimes wonder if the gain > in simplicity from not having to dynamically reload resources is worth > it. > > The way I do something similar in my app is like Streets of Boston, > basically have a callback interface that's stuffed into a static > field. Of course you MUST be careful with locking, you can't just do > something like: > > mCallback.showProgress(progress); > > because mCallback might have been set to null during the brief moment > in which the screen is rotating. But then this is also wrong: > > if (mCallback != null) mCallback.showProgress(progress); > > because it has a race. So you need something like > > synchronized (some object) { > if (mCallback != null) mCallback.showProgress(progress); > } > > and then in your oncreate/ondestroy make sure you synchronize on that > object when setting the value of mCallback. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

