EventBus 是人们在日常开发中经常会用到的开源库,即使是不直接用的人,也多少借鉴过事件总线的用法。而且EventBus的代码其实是非常简单的,可以试着阅读一下。
源码阅读系列不采用对功能进行归类的方法进行阅读,而是采用一个刚开始阅读源码的视角,从我们平时的API调用,一步步的去理解设计意图和实现原理。
从这里开始
从这里开始吧,我们最常用的地方就是给一个函数添加上注解,我们先抛开apt生成的table,只看这个运行时版本的订阅设定。
// eventbus/Subscribe@Documented@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.METHOD})public @interface Subscribe { ThreadMode threadMode() default ThreadMode.POSTING; /** * If true, delivers the most recent sticky event (posted with * {@link EventBus#postSticky(Object)}) to this subscriber (if event available). */
boolean sticky() default false; /** Subscriber priority to influence the order of event delivery. * Within the same delivery thread ({@link ThreadMode}), higher priority subscribers will receive events before * others with a lower priority. The default priority is 0. Note: the priority does *NOT* affec

