Joke Collection Website - Public benefit messages - Android messaging BroadCast, Handler and EventBus advantages and disadvantages

Android messaging BroadCast, Handler and EventBus advantages and disadvantages

Broadcasting is the method that consumes the most time and space. It is one of the four major components. Many system-level events are notified through broadcasts, such as changes in power, network changes, SMS reception and occurrence status, etc.

Advantages: Closely connected with SDK, very convenient when you need to interact with Android. And cross-process communication can be achieved. Activity can be started when necessary

Disadvantages: It takes up a lot of resources and needs to rely on Context

Handlers are generally used for inter-thread communication. The handler's definition class and internal class are bound, which results in high coupling between event publishers and receivers. The most obvious advantage of using handlers is that when a problem occurs, it can be located very clearly and quickly.

The advantage of eventbus is that it is flexible in scheduling, does not need to rely on Context, and does not have coupling like Handler. Inheritability, priority, and stickiness are the biggest advantages of EventBus over BroadCast and observers. The disadvantages are also obvious. Event distribution in EventBus is determined by the parameter type of the annotation function, which makes it difficult to sort out the message flow when there are too many receivers or the same parameters.