Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Add @Receiver to inject the annotated receiver #852

Description

@PerfectCarl

Android Receiver can be registered with code like this:

    ModuleDownloadedReceiver receiver = ...

    private void registerReceiver() {
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.DOWNLOAD_COMPLETE");
        context.registerReceiver(receiver, filter);
    }

But if the receiver has been annotated like this:

@EReceiver
public class ModuleDownloadedReceiver extends BroadcastReceiver {

    @Bean
    ModuleUtils moduleUtils;

}

... there is no annotation to inject the annotated receiver.
What I propose is a new @receiver annotation that would work pretty much like @Bean :

     @Receiver  
     ModuleDownloadedReceiver receiver ;

Activity

  1. DayS commented on Jan 2, 2014

    @DayS
    Contributor

    Why not. And it doesn't cost much :)

  2. yDelouis commented on Jan 2, 2014

    @yDelouis
    Contributor

    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).
  3. PerfectCarl commented on Jan 3, 2014

    @PerfectCarl
    ContributorAuthor

    @yDelouis :+1
    But then it is slightly more then.... :)

    The added benefit of this annotation would be to keep the AndroidManifest leaner for BroadcastReceiver that leaves only in one Activity's context.

  4. DayS commented on Jan 3, 2014

    @DayS
    Contributor

    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

  5. WonderCsabo commented on Jan 12, 2014

    @WonderCsabo
    Member

    I think we should handle LocalBroadcastManager somehow. For example we could add a local method to @Receiver, which is false by default.

  6. yDelouis commented on Jan 13, 2014

    @yDelouis
    Contributor

    I added the local parameter into my PR.

  7. WonderCsabo commented on Jan 13, 2014

    @WonderCsabo
    Member

    Great! Thank you very much. I hope it will be merged soon.

  8. DayS commented on Mar 16, 2014

    @DayS
    Contributor

    Merged :)

  9. WonderCsabo commented on May 28, 2014

    @WonderCsabo
    Member

    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.

  10. PerfectCarl commented on May 28, 2014

    @PerfectCarl
    ContributorAuthor

    Oops, indeed. The final implementation is very different from my initial proposal.
    Okay, I need to do some more research about this :)

  11. WonderCsabo commented on May 31, 2014

    @WonderCsabo
    Member

    I read the updated doc, very nice work!

  12. PerfectCarl commented on May 31, 2014

    @PerfectCarl
    ContributorAuthor

    Added IntentService #1019 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions