EventBus3.0性能优化问题
引入
api 'org.greenrobot:eventbus:3.1.1'
annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.1.1'
生成索引文件
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments = [eventBusIndex: 'com.kawa.easyconvey.MyEventBusIndex']
}
}
}
生成地址
然后在
Application-》onCreate配置下面的代码
EventBus.builder().ignoreGeneratedIndex(false).addIndex(new MyEventBusIndex()).build();
addIndex这里是添加你刚刚生成的类的,该类包含了订阅者和订阅者方法的相关信息
如果你配置好了订阅者索引,下面代码就不会跑用反射获取订阅者方法,而是直接从getSubscriberInfo这个方法里面获取,这个方法里面就是处理你添加的订阅者索引数据的
http://greenrobot.org/eventbus/documentation/subscriber-index/