当前位置:网站首页>EventBus系列:Event Bus 3.0中索引Subscriber Index使用指南
EventBus系列:Event Bus 3.0中索引Subscriber Index使用指南
2022-08-07 01:25:00 【zhangjin1120】
为什么要使用索引?
Subscriber Index(订阅者索引)是一个可选择的优化技术,用来加速初始化subscriber注册。具体怎么加速的,有时间再研究吧!
怎么用?
以下是Gradle 3.0中配置方式-annotationProcessor方式,其中步骤4为重点,我当初按照前三个步骤设置完毕后,竟然一直添加不成功,生成不了目标类。
1、在项目的build.gradle中添加对EventBus库的引用,需要引入EventBus库eventbus工程和注解编译器eventbus-annotation-processor
2、为了使注解编译器自动生成索引类,需要在指定索引类名的全路径。
javaCompileOptions {
annotationProcessorOptions {
// 这里com.example.myapp为你开发所在项目的包名,MyEventBusIndex为类名,可任意指定
arguments = [ eventBusIndex : 'com.example.myapp.MyEventBusIndex' ]
}
}
3、最终在build.gradle文件中的样式为:
android {
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
// 这里com.example.myapp为你开发所在项目的包名,MyEventBusIndex为类名,可任意指定
arguments = [ eventBusIndex : 'com.example.myapp.MyEventBusIndex' ]
}
}
}
}
dependencies {
implementation 'org.greenrobot:eventbus:3.1.1'
annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.1.1'
}
4、也是重点的步骤,初学者往往会有疑惑的地方
如果此时,重新编译工程,然后按照EventBus给出的教程添加索引初始化时,会提示找不到MyEventBusIndex类。原因是此时工程中还没有使用@SubScribe注解,所以注解编译器无法生成MyEventBusIndex类。所以需要先使用@SubScribe注解之后,重新编译,即可生成MyEventBusIndex类,然后使用
边栏推荐
- Service:服务发现与负载均衡
- 加载时动画
- php generate pdf image to pdf
- 桥接模式
- Introduction to Ftrace function graph
- [Microservice Architecture] Introduction and Practice of Link Tracking Skywalking
- 实时图计算如何进行风控决策管理?
- 普林斯顿微积分读本04第三章--极限导论
- Distillation Learning Framework Cheat Sheet (1)
- 1408. A daily topic 】 【 string matching of the array
猜你喜欢
随机推荐
cmake入门
TIDB-PD-RECOVER的恢复方式
04 多线程与高并发 - ReentrantReadWriteLock 源码解析
Apache APISIX Ingress v1.5-rc1 released
CV领域经典backbone模型小抄(2)
习题:循环结构(一)
【8.6】代码源 - 【前缀集】【矩阵游戏】【谁才是最终赢家?】
LeetCode:每日一题【第一周】
LabVIEW如何使用热键去触发自定义的事件
开启了j-proxy, 会导致xcode无法正常连接到app store和开发者中心
unity UI、 粒子 、3d模型,按钮如何设置显示
在线问题反馈模块实战(二十一):完结篇
切换时过渡和动画
【LeetCode】300.最长递增子序列
Qt QDir相关笔记
禁用防火墙后,aria2的6800端口还是不通
连接 MySQL 报错:2059 - authentication plugin ‘caching_sha2_password‘ cannot be loaded...
Opencv立体相机标定
语音识别与转换小试牛刀(1)
Dark horse 2022 latest redis course notes and knowledge points (for interviews) are continuously updated









