订阅者类android.app.Application没有名为onEvent

时间:2015-05-17 19:37:29

标签: android greenrobot-eventbus

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

我想要的是当我使用后退按钮将事件发送到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上注册/取消注册EventBus然后我尝试在BottomBar类上注册eventBus但是我得到了帖子标题中的例外:

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

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

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

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

1 个答案:

答案 0 :(得分:3)

  

我在BottomBar中有onEvent

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