Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
活动能否在EventBus Android中同时注册粘性和非粘性事件_Android_Greenrobot Eventbus - Fatal编程技术网

活动能否在EventBus Android中同时注册粘性和非粘性事件

活动能否在EventBus Android中同时注册粘性和非粘性事件,android,greenrobot-eventbus,Android,Greenrobot Eventbus,在我的活动中,我想为[Sticky和Noo Sticky事件]注册它。因为我正在发布服务中的两种类型的事件,这些事件应该在我的活动中触发 通常,我想实现这一点 EventBus.getDefault().register(this); EventBus.getDefault().registerSticky(this); 然后想在 public void onEvent(EventSticky1 event){ // code here ... } public void onEve

在我的活动中,我想为[Sticky和Noo Sticky事件]注册它。因为我正在发布服务中的两种类型的事件,这些事件应该在我的活动中触发

通常,我想实现这一点

EventBus.getDefault().register(this);
EventBus.getDefault().registerSticky(this);
然后想在

public void onEvent(EventSticky1 event){
     // code here ...
}
public void onEvent(EventNonSticky1 event){
         // code here ...
}
但是,这给了我如下所示的错误

de.greenrobot.event.EventBusException: Subscriber class MainActivity already registered to event class EventSticky1
                                                     at de.greenrobot.event.EventBus.subscribe(EventBus.java:179)
                                                     at de.greenrobot.event.EventBus.register(EventBus.java:165)
                                                     at de.greenrobot.event.EventBus.registerSticky(EventBus.java:151)
如何才能做到这一点

提前谢谢