Monday, January 31, 2011

[android-developers] Re: Should a service maintain a reference to a Broadcast Receiver

On Jan 31, 8:14 pm, AndroidDevTime <androiddevd...@gmail.com> wrote:
> Is it a bad practice to maintain a service level reference to a
> BroadcastReceiver?  I do see there is a service level method
> service.registerReceiver ....  Under what situations is it appropriate
> to register the BroadcastReceiver with a service?

registerReceiver is actually a method defined by Context, from which
Activities, Services, and Application all inherit. You register a
broadcast receiver in a Service when that service needs to know about
a broadcast during its lifetime, just like any Activity. In other
words, there's nothing to sweat. Just unregister it before it's
destroyed.

> To hold a static
> reference to a broadcast receiver in a service?  Thanks.

That won't fly with Android. When a Service is destroyed, and you
haven't unregistered all your receiver, Android will complain and
force them to become unregistered, just like Activities. Anyway, what
are you doing that makes it necessary to have a static member in a
Service?

Doug

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment