Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.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
Android 如何取消订阅自己发送的EventBus事件?_Android_Event Bus_Greenrobot Eventbus - Fatal编程技术网

Android 如何取消订阅自己发送的EventBus事件?

Android 如何取消订阅自己发送的EventBus事件?,android,event-bus,greenrobot-eventbus,Android,Event Bus,Greenrobot Eventbus,我已经为EventBus事件注册了两个跑步类-实例A和实例B。它们都实现了onEvent(SampleEvent事件)方法来接收EventBus.post(newsampleevent(intfoo,stringbar))从一个位置C。到目前为止还不错 但是有一段时间我需要将SampleEvent从B发布到a。是否可以告诉B它不应该处理自己发送的SampleEvent,或者我需要做一些变通,比如在SampleEvent中设置一个标志?您可以尝试将exmaple SampleEvent的Sampl

我已经为EventBus事件注册了两个跑步类-实例A和实例B。它们都实现了
onEvent(SampleEvent事件)
方法来接收
EventBus.post(newsampleevent(intfoo,stringbar))从一个位置C。到目前为止还不错


但是有一段时间我需要将SampleEvent从B发布到a。是否可以告诉B它不应该处理自己发送的
SampleEvent
,或者我需要做一些变通,比如在
SampleEvent
中设置一个标志?

您可以尝试将exmaple SampleEvent的SampleEvent扩展到a,而不是使用反射在B中检查:

if  (! event instanceof SampleEventA){
    //do things here
}
在otto EventBus上发现此问题:来自超级事件的派生事件也将调用超级事件的订阅者。这将是一个可能的OO解决方案


为什么在将事件从B发送到a时不使用单独的事件?@PeterP这也是一种方法。问题是,它将是完全相同的事件,具有相同的变量,只是名称不同。如果我的想法不可能实现,我会走这条路谢谢,我没想到的好主意。然而,这并不是我想要的答案。