2

i am using EventBus on activity and override one event ABC. now i am calling that event from multiple classes (EventBus.getDefault().post(new ABC()) etc.) and i am getting callback on my activity class. so my question is : is there any way to identify caller who called that event on my activity class.

alessandrio
  • 4,282
  • 2
  • 29
  • 40
Swapnil
  • 654
  • 7
  • 27

2 Answers2

0

Put something in ABC that tells you where the event originated from, such as via a constructor parameter.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

I'd suggest adding a constructor which receives a tag

public ABC(int tag) {}

And then in your Activity you can proceed like this:

@Subscribe()
public void onEvent(ABC event) {
    switch(event.getTag()) {
        case MyService.TAG: 
            //process data from your service
            break;
        case MyFragment.TAG: 
            //process data from your fragment
            break;
    }
}