订阅者 class android.app.Application 没有 public 方法调用 onEvent

Subscriber class android.app.Application has no public methods called onEvent

我已将我的一些视图从 Activity 委托给名为 BottomBar 的 class。

我想要的是当我按下后退按钮时向 BottomBar 发送一个事件以便开始播放动画。

@Override
public void onBackPressed() {
    if (isSubMenuDisplayed) {
        isSubMenuDisplayed = false; 
        EventBus.getDefault().post(new EventStartReverseAnimation(true));
        //post event to fragment
    } else {
        super.onBackPressed();
    }
}

这是我的 onBackPressed() 代码,我在 BottomBar 中有 onEvent :

public void onEventStartReverseAnimation(EventStartReverseAnimation event) {
    swedsFlag = event.getFlag();
    if (swedsFlag) {
        playBackAnimation(true);
    }
}

当然,我在 Activity 上 register/unregister EventBus,然后我尝试在 BottomBar class 上注册 eventBus,但我得到了 post 标题中的异常:

 de.greenrobot.event.EventBusException: Subscriber class android.app.Application has no public methods called onEvent

应用程序在我为 BottomBar 注册 EventBus 的行崩溃 class :

    public BottomBar(Context context) {
    this.context = context;
    myServiceClient = new MyServiceClient();
    myServiceClient.initializeRestClient();
    bbUtils = new BottomBarUtils(context);

    EventBus.getDefault().register(context);
} 

I have onEvent in BottomBar

不,根据该代码片段,您没有。你有 onEventStartReverseAnimation()。将该方法重命名为 onEvent(),或 onEventMainThread(),或其他受支持的方法名称之一。