EventBus 学习
官方网址:http://greenrobot.org/eventbus/
Github网址:https://github.com/greenrobot/EventBus
介绍:
EventBusis an open-source library for Android using thepublisher/subscriberpattern for loose coupling(松耦合). EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code(简化代码), removing dependencies(解除依赖), and speeding up app development.
Github:Android optimized event bus that simplifies communication betweenActivities,Fragments,Threads,Services,etc. Less code, better quality.
EventBus Benfit:
simplifies the communication between components
decouples(解耦) event senders and receivers
performs well with Activities, Fragments, and background threads
avoids complex and error-prone dependencies and life cycle issues
is fast; specifically optimized(优化) for high performance
is tiny (<50k jar)
isproven in practice by apps with 100,000,000+ installs
has advanced features like delivery threads, subscriber priorities(优先), etc.
Further EventBus Features
Simple yet powerful:EventBus is a tiny library with an API that is super easy to learn. Nevertheless, your software architecture may great benefit by decoupling(解耦) components: Subscribers do not have know about senders, when using events.
Battle tested:EventBus is one of the most used Android libraries: thousands of apps use EventBus including very popular ones. Over a billion app installs speak for themselves.
High Performance:Especially on Android, performance matters(性能问题). EventBus was profiled and optimized(优化) a lot; probably making it the fastest solution of its kind.
Convenient(方便的) Annotation based API:Simply put the @Subscribe annotation to your subscriber methods. Because of a build time indexing of annotations, EventBus does not need to do annotation reflection during your app’s run time.
Android main thread delivery(分发):When interacting with the UI(当和UI交互), EventBus can deliver events in the main thread regardless how an event was posted.
Background thread delivery:If your subscriber does long running tasks, EventBus can also use background threads to avoid UI blocking.
Event & Subscriber inheritance(继承):In EventBus, the object oriented paradigm apply to event and subscriber classes. Let’s say event class A is the superclass of B. Posted events of type B will also be posted to subscribers interested in A. Similarly the inheritance of subscriber classes are considered.
Jump start:You can get started immediately – without the need to configure anything – using a default EventBus instance available from anywhere in your code.
Configurable(可配置):To tweak EventBus to your requirements, you can adjust its behavior using the builder pattern.
EventBus Documentation
链接:http://greenrobot.org/eventbus/documentation/how-to-get-started/