Hello.

I've been doing background tasks and they work, but I'm interested in 
best practice. I think this has been talked about on the list before, 
but I haven't seen a clear discussion, and one of Streets of Boston's 
posts yesterday got me thinking.

Say you have a background chore that needs to return results to the 
UI. You use AsyncTask or cook-up something on your own and the work 
gets done.

Now you need to notify the UI. So you post a Runnable or Message. Fine.

But let's say the user moved away from the invoking activity while 
the background thread was running, or changed orientation, so the 
result receiving activity is either no longer foreground or different.

If the user moved away from the initiating activity, the results 
arrive in the handler of a "zombie" activity no longer being 
displayed (but which can, I guess, now be garbage collected since the 
reference to the activity in the result message has been released). 
Is there anything to worry about here, or is it OK to mindlessly 
update a non-displayed view tree....?

If orientation has changed, the results are delivered to the "wrong" 
handler in the old activity. This is more of a problem. I've hacked 
around this in various ways, but they are all kind of clunky -- 
involving having activities "register" in some way with the 
background task so results go to the correct handler. Is there a more 
elegant approach?

I may be totally over thinking this, since my previous approaches 
work, but this morning I'm off to write more background code and I'd 
like to handle result delivery in a way that is "pretty." I also want 
to be sure I'm not making some obvious conceptual mistake in my 
mental model of all this.

Thanks smart people,

-- Ward

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

Reply via email to