Reputation: 835
I have delegated some of my Views from Activity to a class named BottomBar.
What I want is when I the back button to send an event to the BottomBar so an animation starts to play.
@Override
public void onBackPressed() {
if (isSubMenuDisplayed) {
isSubMenuDisplayed = false;
EventBus.getDefault().post(new EventStartReverseAnimation(true));
//post event to fragment
} else {
super.onBackPressed();
}
}
This is my code for onBackPressed() and I have onEvent in BottomBar :
public void onEventStartReverseAnimation(EventStartReverseAnimation event) {
swedsFlag = event.getFlag();
if (swedsFlag) {
playBackAnimation(true);
}
}
Ofcourse I register/unregister EventBus on Activity and then I try to register eventBus on the BottomBar class but I get the exception I have in the post title :
de.greenrobot.event.EventBusException: Subscriber class android.app.Application has no public methods called onEvent
The app crashes at the line where I register EventBus for BottomBar class :
public BottomBar(Context context) {
this.context = context;
myServiceClient = new MyServiceClient();
myServiceClient.initializeRestClient();
bbUtils = new BottomBarUtils(context);
EventBus.getDefault().register(context);
}
Upvotes: 0
Views: 1828
Reputation: 1006674
I have onEvent in BottomBar
No, you do not, according to that code snippet. You have onEventStartReverseAnimation()
. Rename that method to be onEvent()
, or onEventMainThread()
, or one of the other supported method names.
Upvotes: 3