I have a function that add custom listeners to the same trigger event.
So the same event can trigger multiple listeners, this is working. What I would like is: if I have 3 listeners (for example) be able to remove just one of then and let the other two working.
This is my function to add events, they are in a Map<String, CustomListener>
variable.
void addEventListener(String eventName, EventListener eventListener) {
List<eventListener> eventListenerList = new ArrayList<>();
if (eventListenerMap.containsKey(eventName)) {
eventListenerList = eventListenerMap.get(eventName);
}
Objects.requireNonNull(eventListenerList).add(eventListener);
eventListenerMap.put(eventName, eventListenerList);
}
And this is my function to remove
void removeEventListener(String eventName, EventListener eventListener) {
if (eventListenerMap.containsKey(eventName)) {
List<InsEventListener> eventListenerList = eventListenerMap.get(eventName);
assert eventListenerList != null;
eventListenerList.remove(eventListener);
eventListenerMap.put(eventName, eventListenerList);
}
else {
Log.w("Remove Event Listener:", "Event not found");
}
}
As you can see in the image below, it recognise the same class with the same lamba address, but it won't remove.
Obs: all the listeners are called in the same function in the same place