我在我的安卓应用程序中使用了RoboGuice 3.0.1和RoboBlender。我想要有一个全局事件管理器,并注意到RG3.0已经有了这里提到的:https://github.com/roboguice/roboguice/issues/150
我已经添加了
bind(EventManager.class).annotatedWith(Names.named(DefaultRoboModule.GLOBAL_EVENT_MANAGER_NAME)).to(EventManager.class).asEagerSingleton();在configure()中添加到我的自定义模块类。
我有一个执行web请求的单例WebUtil.class。我希望在API请求完成后使用全局事件管理器发送事件。我已经使用以下命令注入了eventManager:
@Inject EventManager eventManager;事件是通过以下方式发送的:
eventManager.fire(new MyAPIEvent());我的Activity类中有一个观察者方法:
handleAPICallback(@Observes MyAPIEvent apiEvent) {
// do something with apiEvent object
}但是我没有看到handleAPICallback()被调用。我在网上搜索,没有找到一个GlobalEventManager的例子。
任何帮助都将不胜感激。
发布于 2015-03-25 06:19:21
我通过在RG的github页面上发帖解决了这个问题。这是链接:https://github.com/roboguice/roboguice/issues/288#issuecomment-69770596
已测试并验证其工作正常。
https://stackoverflow.com/questions/27616198
复制相似问题