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.
Asked
Active
Viewed 146 times
2

alessandrio
- 4,282
- 2
- 29
- 40

Swapnil
- 654
- 7
- 27
2 Answers
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;
}
}

Konstantin Kiriushyn
- 627
- 6
- 13