2

I am using Greenrobot EventBus 3.0.0. I have a class A and it received an Object Event.In class A I modified that object and pass it to next Activity B.

@Override
    protected void onStart() {
        super.onStart();
  EventBus.getDefault().register(this);
  }


    @Override
    public void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    } 


@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void onRowClicked(RequestDTO requestDTO) {
        if (requestDTO!= null) {
            EventBus.getDefault().post(requestDTO);
            startActivity(new Intent(this, ActivityB.class));
        }

    }

The problem is that it stuck in infinite loop because publisher and subscriber same event.How to resolved that issue?

Meonix
  • 33
  • 6

1 Answers1

0

This seems kind hacky. What do you really want to do? You could unregister your current activity just before invoking your second post of your event. But are you sure, that your second activity will be prepared by the Android system, when your event will come in? This is really not the case for EventBus callback. If I were you, I would pass the data in the plain old Intent. Or, If you really need this dynamics - you could manually call your onRowClicked method of your ActivityB with that modified RequestDTO object

kaplis
  • 63
  • 7