设置自定义侦听器以侦听整个应用程序
Set a custom listener to listen throughout the whole application
我想知道是否可以让 1 个侦听器在整个应用程序中侦听特定事件。
此时我已经创建了自己的监听器,它正在监听一个事件的发生,但是当我切换到另一个时它应该仍然监听这个事件activity。
使用 http://square.github.io/otto/ 进行事件监听。
这是一个用法示例:
Bus bus = new Bus();
bus.post(new AnswerAvailableEvent(42));
@Subscribe public void answerAvailable(AnswerAvailableEvent event) {
// TODO: React to the event somehow!
}
bus.register(this); // In order to receive events, a class instance needs to register with the bus.
我想知道是否可以让 1 个侦听器在整个应用程序中侦听特定事件。
此时我已经创建了自己的监听器,它正在监听一个事件的发生,但是当我切换到另一个时它应该仍然监听这个事件activity。
使用 http://square.github.io/otto/ 进行事件监听。
这是一个用法示例:
Bus bus = new Bus();
bus.post(new AnswerAvailableEvent(42));
@Subscribe public void answerAvailable(AnswerAvailableEvent event) {
// TODO: React to the event somehow!
}
bus.register(this); // In order to receive events, a class instance needs to register with the bus.