On Sat, Oct 24, 2009 at 9:47 AM, Mark Murphy <[email protected]>wrote:

> > new Handler().postDelayed(someTask, someTime);
> I have not used Handler inside a Service, and so I have no idea whether
> or not that's a good idea.
>

Handler and the related message loop APIs are much much lower-level than
Service, Activity, etc, so it doesn't matter "where" you do this stuff from,
it is completely unaware of that.

The only thing that the above code does is create a new Handler (associated
with the main thread/looper of the process since presumably this is being
done in one of the Service callbacks like onCreate()), and placing
"someTask" on the message list of that main thread/looper with the created
Handler as the destination for it.

Now one thing that may be happening here is that "someTask" is some inner
class of the service, which would mean that as a side-effect you are
creating a reference on the service (because the message is on the thread's
message queue, so it has a reference on it until it is dispatched, and it
has a reference on someTask, and someTask being an inner class of the
service has a reference on the service).  This would prevent the Service
from being garbage collected, even though it is technically no longer used
(its onDestroy() has been called) nor valid.

>From what I have heard so far, my suspicion is that whatever the original
code is, it is really not using these things correctly at all.

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

Reply via email to