Global Event Manager Roboguice

2019-07-22 08:41发布

问题:

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.

回答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.