EventBus icon indicating copy to clipboard operation
EventBus copied to clipboard

Do not throw on register if the registered class has no onEvent

Open benoitdion opened this issue 10 years ago • 11 comments

This makes it easier to do the registration in a base class where some of the derived class may not subscribe to any event.

benoitdion avatar Jan 21 '14 03:01 benoitdion

I would also like a flag to disable the exception, because of a very similiar reason then the above.

timroes avatar Jan 21 '14 07:01 timroes

What I do is subscribe to a pointless 'dummy event' in my BaseActivity. Not elegant, but better than subscribing in every Activity that I derive from it.

fmweigl avatar Jan 23 '14 07:01 fmweigl

Use case makes sense. Wonder if we can configure this behavior elegantly.

greenrobot avatar Jan 23 '14 10:01 greenrobot

On the other hand you can wrap the registration with a try/catch and log it. it makes sense If you already know you might have a derived class with no event listeners.

danielbenzvi avatar Feb 01 '14 01:02 danielbenzvi

Not sure if that should be implemented using #124 or some registration flags (planned for a future version). Against #124 speaks that it would not complain if the completely wrong object gets registered.

greenrobot avatar Nov 09 '14 21:11 greenrobot

In JPA (Java Persistence API) we have the annotation @ExcludeSuperclassListeners. When a subclass is flagged with this annotation she becomes ignored. What do you think of this solution?

RicardoRFaria avatar Jun 16 '15 17:06 RicardoRFaria

@RoxRicardo Sounds good, will think about it. Eventually there will be a single @Subscriber annotation to customize, so there might be a property for that, e.g. @Subscriber(ignoreNoSubscribers = true).

greenrobot avatar Jun 16 '15 18:06 greenrobot

@greenrobot i'm interested in contribute, can you suggest some feature of backlog?

RicardoRFaria avatar Jun 16 '15 18:06 RicardoRFaria

Has a proper solution for this issue been released?

aneemtalukder avatar Nov 28 '16 15:11 aneemtalukder

@aneemtalukder You still have to make sure to have at least one method annotated with @Subscribe before calling .register() or EventBus will throw an exception. -ut

greenrobot-team avatar Nov 29 '16 06:11 greenrobot-team

still no change? a configuration in the builder to ignore this error would be awesome

mlostekk avatar Feb 13 '18 17:02 mlostekk