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
-~----------~----~----~----~------~----~------~--~---