How can I create multiple events using an event bus?
So in this example, I'm trying to receive multiple events. But when addEvent3WhenLogicOccers()
is called values of addEvent1WhenLogicOccers()
are gone because of new EventBusEvents()
in the event bus post. I want to receive both EVENT_1
and EVENT_3
with their data which is my_event_child_1
and my_event_child_3
. How can I do it?
String EVENT_1 = "my_event_child_1";
String EVENT_2 = "my_event_child_2";
String EVENT_3 = "my_event_child_3";
addEvent1WhenLogicOccers() {
EventBus.getDefault().postSticky(new EventBusEvents(EVENT_1));
}
addEvent3WhenLogicOccers() {
EventBus.getDefault().postSticky(new EventBusEvents(EVENT_3));
}
@Subscribe(sticky = true)
public void onEvent(EventBusEvents eventBusEvents) {
switch(eventBusEvents.eventChilds) {
case EVENT_1:
// on event 1 code
break;
case EVENT_2:
// on event 2 code
break;
case EVENT_3:
// on event 3 code
break;
}
}
I found out EventBus
wasn't the best solution for me. I used interfaces instead HERE