1

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);
}
fatih
  • 1,285
  • 11
  • 27

1 Answers1

0

Replace your subscribe method like this :-

@Subscribe(threadMode = ThreadMode.MAIN)  
public void onMessageEvent(MessageEvent event) {
---
};

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

Ganesh K
  • 126
  • 14
  • I have created MessageEvent object. I tried that, but the problem continues. – fatih Sep 21 '18 at 18:57
  • You are missing threadMode line in the @Subscribe annotation. Please add that and see if your problem is resolved – Ganesh K Sep 22 '18 at 07:54