用于Android应用的一个轻量级的和简单的事件总线:tinybus
jopen
10年前
专为Android设计的一个轻量级的和简单的事件总线。
TinyBus is
- fast (optimized for startup and event dispatching)
- tiny (~ 17K jar)
- well tested (> 50 junit tests)
- annotation based (no requiremens to method names, no interfaces to implement)
Performance comparison tests
Executed on Galaxy Nexus device with Android 4.3 (Dalvik) with switched off screen.
TinyBus quick start
// 1. Create event public class LoadingEvent { // some fields if needed } // 2. Prepare event subscriber (Activity, Fragment or any other component) @Subscribe public void onEvent(LoadingEvent event) { // event handler logic } bus.register(this); // 3. post event bus.post(new LoadingEvent());
For a more detailed example check out Getting started step-by-step guide or example application.
TinyBus 可以帮助
- 去除不必要的接口和直接组件的依赖
- 简化 Activities, Fragments 和 Services之间的通信
- 简化后台线程和主线之间的事件交互
- 简化的标准系统事件的消费(like Battery Level, Connection State etc.)
项目主页:http://www.open-open.com/lib/view/home/1416301561367