EventBus serves as the communication between components, and EventBus Components

Source: Internet
Author: User
Tags eventbus

EventBus serves as the communication between components, and EventBus Components

1. Why use EventBus?

Generally, the following mode is used for communication between different activty and other components:

Is to define an interface, you need to pay attention to the event to implement this interface. Then, register or cancel the controls that interest the event when the event is triggered, as described in the following article:

Decouples communication between Android App components in Event Bus mode

This problem is also obvious, that is, the coupling between different components is often severe, and more interfaces are difficult to maintain, in this way, the EventBus mode is used to solve the communication between components with low coupling.

2. EventBus class library Introduction

EventBus is a release/bus mode optimized Android system library.


  • Simplifies communication between components
    • Events senders and receivers are decoupled.
    • It works well in Activities, Fragments, and background threads.
    • This avoids complex and error-prone dependencies and lifecycles.
  • Make your code more concise
  • Faster running
  • Smaller class library (<50 k jar)
  • Already used in more than 100,000,000 installed Apps
  • There are some advanced features such as delivery threads and subscriber priorities.

  • EventBus uses three steps
    1. Define events:
      public class MessageEvent { /* Additional fields if needed */ }

    2. Prepare subscribers:
      eventBus.register(this);
      public void onEvent(AnyEventType event) {/* Do something */};

    3. Post events:
      eventBus.post(event);
    The following is an online EventBus instance:
  • Http://blog.csdn.net/jdsjlzx/article/details/40856535


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.