I am using EventBus to send the long
value from a fragment
to another
fragment. I use the following code to do that. But for me, it doesn't work. What did I do wrong?
This is the fragment where I save the data:
@OnClick(R.id.buttonFinishMeeting)
public void onClickButton() {
startActivity(RoutePlanCompleteActivity.newIntent(getContext(), routePlan));
EventBus.getDefault().post(new Long(spentTime));
}
Then the fragment I want to send my data:
@Subscribe
public void onEvent(Long time) {
spentTime = time;
}
@Override
public void onResume() {
super.onResume();
EventBus.getDefault().register(this);
}
@Override
public void onPause() {
super.onPause();
EventBus.getDefault().unregister(this);
}
Replace your subscribe method like this :-
This code has been taken from the official documentation of Eventbus from here. If you have any more trouble, visit this link https://github.com/greenrobot/EventBus