全球事件管理器Roboguice [英] Global Event Manager Roboguice

查看:135
本文介绍了全球事件管理器Roboguice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序中使用RoboGuice 3.0.1 RoboBlender一起。
我想有一个全球性的事件管理器,发现RG3.0已经拥有了在这里提到:
https://github.com/roboguice/roboguice/issues/150

我已经加入

<$p$p><$c$c>bind(EventManager.class).annotatedWith(Names.named(DefaultRoboModule.GLOBAL_EVENT_MANAGER_NAME)).to(EventManager.class).asEagerSingleton();

我的自定义模块类的内部配置()。

我有一个执行的Web API请求的单WebUtil.class。我想利用全球事件管理器发出的事件一次的API请求完成。
我已经注射用eventmanager进行:

  @Inject eventmanager进行eventmanager进行;

活动使用送出:

  eventManager.fire(新MyAPIEvent());

我有一个观察的方法在我的活动类:

  handleAPICallback(@Observes MyAPIEvent apiEvent){
//做apiEvent对象的东西
}

但我没有看到handleAPICallback()被调用。
我在网上搜索,找不到了GlobalEventManager一个例子。

任何帮助将大大AP preciated。


解决方案

我张贴的RG GitHub的页面上解决了这个问题。
这里是链接:
https://github.com/roboguice/roboguice/issues/288#issuecomment-69770596

测试和验证,它的作品。

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.

解决方案

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.

这篇关于全球事件管理器Roboguice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆