EventBus icon indicating copy to clipboard operation
EventBus copied to clipboard

Allow registration of classes without any subscriptions

Open veeti opened this issue 8 years ago • 3 comments

For automatic registration in base classes where some defined children might not have any subscriptions. This could be a configuration value on the bus or a registerOptional method.

veeti avatar Mar 27 '16 20:03 veeti

:+1:

eku avatar Mar 28 '16 13:03 eku

Why not move the register call to an overridable method that you overwrite empty in the child classes that should not register to EventBus? Would make it much more clear which classes register and which not and void the performance overhead of searching for subscriber methods.

Something like:

public abstract class BaseClass {
    protected void registerEventBus() {
        EventBus.getDefault().register(this);
    }
}
public class ChildClass extends BaseClass {
    @Override
    protected void registerEventBus() {
        // do not register to EventBus
    };
}

-ut

greenrobot-team avatar Jul 04 '16 07:07 greenrobot-team

Because I'm honestly just not interested in keeping track of which child class is registering on the bus and which is not. I want to add a subscription to any activity/fragment at any time and have it just work. Whatever tiny performance overhead this adds is worth the developer comfort.

If anyone else is looking for this, my current workaround is to add a subscription on a dummy class inside the base class.

veeti avatar Jul 04 '16 08:07 veeti