Priorities and Event Cancellation

While most use cases of EventBus do not need priorities nor event cancellation, they may come in handy in some special cases. For example, an event may trigger some UI logic if the app is in the foreground, but react differently if the app is currently not visible to the user.

Subscriber Priorities

You may change the order of event delivery by providing a priority to the subscriber during registration.

Within the same delivery thread (ThreadMode), higher priority subscribers will receive events before others with a lower priority. The default priority is 0.

Note: the priority does not affect the order of delivery among subscribers with different ThreadModes!

Cancelling event delivery

You may cancel the event delivery process by calling cancelEventDelivery(Object event) from a subscriber’s event handling method. Any further event delivery will be cancelled, subsequent subscribers won’t receive the event.

Events are usually cancelled by higher priority subscribers. Cancelling is restricted to event handling methods running in posting thread ( ThreadMode.PostThread).

Spread the love