On Thu, Dec 1, 2011 at 8:44 AM, lbendlin <l...@bendlin.us> wrote:
> I have a service S and a bunch of activities A,B,C,D etc.  The service S is
> sending broadcasts. Activity A is currently manually registering a
> broadcastreceiver on onResume and unregistering the receiver on onPause.
> But I was thinking if it is possible to do all this "automagically" through
> the manifest, and to do away with the register/unregister calls.
>
> Like, list the broadcast as an action filter for activity A, and then
> somehow explain to the constructor of activity A that it should also behave
> like a broadcastreceiver (and serve the onReceive function).

That's not possible. BroadcastReceiver is a class, not an interface.
Activity is a class, not an interface. Java does not support multiple
inheritance, so you cannot inherit from both Activity and
BroadcastReceiver, and "implements" only works with interfaces.

> So how do I tell the activity to listen for the broadcasts?

Use the approach that you already have working.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, One Low Price!

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to