2

I am using RoboGuice 3.0.1 along with RoboBlender in my Android application. I wanted to have a global event manager and noticed that RG3.0 already has it as mentioned here: https://github.com/roboguice/roboguice/issues/150

I have added

bind(EventManager.class).annotatedWith(Names.named(DefaultRoboModule.GLOBAL_EVENT_MANAGER_NAME)).to(EventManager.class).asEagerSingleton();

to my custom module class inside configure().

I have a singleton WebUtil.class that performs a web API request. I want to make use of the global event manager to send out the event once the API request is complete. I have injected the eventManager using:

@Inject EventManager eventManager;

Events are sent out using:

eventManager.fire(new MyAPIEvent());

I have an Observer method in my Activity class:

handleAPICallback(@Observes MyAPIEvent apiEvent) {
// do something with apiEvent object
}

But I don't see the handleAPICallback() being called. I searched online and could not find a single example for the GlobalEventManager.

Any help would be greatly appreciated.

Vijay
  • 435
  • 1
  • 6
  • 16

1 Answers1

1

I solved this question by posting on the github page for RG. Here is the link: https://github.com/roboguice/roboguice/issues/288#issuecomment-69770596

Tested and verified that it works.

Vijay
  • 435
  • 1
  • 6
  • 16
  • As an extra comment, what confused me about this was that I had one component that was, in fact, having its `@Observes` methods registered with the global event manager, and another that was not. Ultimately, it turned out that it DOES work, but you have to configure the component as an EAGER singleton. – Avi Cherry Apr 26 '16 at 23:19