Karpachev  Igor Karpachev Igor - 10 months ago 28
Android Question

How to prevent calling all 'onEvent' methods in class hierarchy

I am struggling with preventing call all methods in class hierarchy chain.
Lets say i have a base class:

class BaseModel

{ /* Some basic fields goes here */ }

class ModelCompany extends BaseModel

{ /* Fields goes here */ }

Then I want to post two different events:

BaseModel oneEvent = new BaseModel();

ModelCompany otherEvent = new ModelCompany();



Somewhere in the activity:

onEvent(BaseModel ev1){}

onEvent(ModelCompany ev2){}

The thing is that both onEvent method will be executed in this case. How to prevent it and post message to exact method?


From EventBus Source, it is recursively looking for super class:

while (clazz != null) {
    clazz = clazz.getSuperclass();

I don't think there is a setting to disable this, as of now.