You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Add @Receiver to inject the annotated receiver #852
The second proposal of the issue #484 seems interesting to me and looks like this proposal.
The main issue is to decide when the BroadcastReceiver should be registered and unregistered (onResume/onPause or onStart/onStop or onCreate/onDestroy).
I propose an annotation @Receiver with two parameters :
actions which is an array of String indicating the action to add to the IntentFilter
registerAt (or another name) which is an enum indicating when the BroadcastReceivershould be registered and unregistered (onResume/onPause or onStart/onStop or onCreate/onDestroy).
So with this annotation the receiver will be injected in the field and automatically registered to the context according to the chosen scope (ie registerAt).
Seems interesting. I'm planning this for 3.1
I think the doc is incorrect. @Receiver is intended to be used on methods, not fields. However we should really provide a way to inject enhanced BroadcastReceivers.
Android
Receivercan be registered with code like this:But if the receiver has been annotated like this:
... there is no annotation to inject the annotated receiver.
What I propose is a new @receiver annotation that would work pretty much like
@Bean: