当前位置:网站首页>组件化学习(3)ARouter中的Path和Group注解
组件化学习(3)ARouter中的Path和Group注解
2022-04-23 06:07:00 【独饮敌敌畏丶】
这里就不对ARouter进行全面分析了,而是把Group和Path的思想抽象出来理解
1.介绍下Group和Path
在上一篇文章中也提到过,Group
就是组,Path
就是组里面具体的类。在ARouter
的api模块中,有针对Group
和Path
的接口ARouterGroup
和ARouterPath
。如下(这里只是举个例子,并不一定真有同名接口,但是思想是一样的)
public interface ARouterGroup {
Map<String, Class<? extends ARouterPath>> getGroupMap();
}
ARouterGroup
接口:
有一个Map
集合,key
,就是各个组名,比如app
,common
等等。value
就是每个组名对应的详情类。其实就是实现了ARouterPath
接口的类.ARouterPath
接口:
public interface ARouterPath {
Map<String, RouterBean> getPathMap();
}
这里的key
就是Path
,value
就是与Path
相对应的,被RouterBean
封装了的class
对象。比如key
是/app/MainActivity
,value
就是RouterBean<MainActivity.class>
RouterBean
就是这样的,其中被框起来的就是Class对象。可以理解成对Class对象的封装
2.Path和Group的工作原理
注意: 先有Path
的接口ARouterPath
,再有Group
的接口ARouterGroup
,因为Group
要遍历使用Path
说到这里,可能还是对ARouterGroup
接口,ARouterPath
接口不太熟悉。我在这里把具体实现的效果拿过来,就好理解多了
在具体实现的时候,即利用JavaPoet生成类文件的时候
①要首先生成,实现了ARouterPath
接口的类。不同的group
有不同的实现类。比如app组就对应一个ARouterPath
的实现类,里面也有一个Map集合,key
可以是app
组里面所有的Path
,value
就是与Path
对应的RouterBean
。
②然后生成实现了ARouterGroup
接口的类。这个类也是一个组对应一个,相当于一个模块对应一个路由表。key
就是不同的组,value
就是不同的组对应的ARouterPath
的实现类。
假如目前只有两个业务模块,即order和personal,则
①生成的实现ARouterPath
接口的类的具体代码实现如图所示
order
模块生成的,里面的Map
集合存储了order模块所有的path
personal
模块生成的
②生成的实现ARouterGroup
接口的类的具体代码实现如图所示
order
板块生成的,里面存储了所有可能用到的模块对应的实现了ARouterPath
的Class对象personal
板块生成的
ARouterManager
是全局的,是用来缓存ARouter$$Group
和ARouter$$Path
的
需要通信的时候,比如order
模块要向personal
模块通信,我认为就需要找全局的ARouterManager
里面有没有缓存的ARouter$$Group$$personal
,如果有,就直接利用缓存的ARouter$$Group$$personal
,找到ARouter$$Path$$personal.class
,然后再得到目标类的 RouterBean
对象,即得到了目标类的class
对象,进行通信,如果没有,就把编译后就生成的ARouter$$Group$$personal
类和ARouter$$Path$$personal
添加到ARouterManager
里面(即懒加载),然后再完成跳转
代码描述就是这样:
ARouter$$Group$$personal.getGroupMap().get("personal").get("targetClass")
ARouter的参数传递,也是类似的思想,和ButterKnife也很像。就是在需要传递的参数定义上面加上注解,然后编译的时候生成特定的类的类文件,这个类文件的作用就是可以使用Bundle
,给对应的类的这些参数赋值
我所理解的Path和Group原理就是这样。具体的生成这些类文件的JavaPoet代码,我还没有进行详细学习,等后面用到的时候再学习吧,现在先掌握思想。
版权声明
本文为[独饮敌敌畏丶]所创,转载请带上原文链接,感谢
https://blog.csdn.net/afdafvdaa/article/details/121672042
边栏推荐
猜你喜欢
Relabel of Prometheus_ Configs and metric_ relabel_ Configs explanation and usage examples
Apache Atlas 编译及安装记录
Redis practice notes and source code analysis
Construire un blog Cloud basé sur ECS (bénédiction sur le Code Cloud Xiaobao, explication détaillée de la tâche iphone13 gratuite)
Build a cloud blog based on ECS (send blessings on the cloud Xiaobao code and draw iphone13 for free)
ACFS文件系统创建扩大缩小等配置步骤
mysql和pgsql时间相关操作
this.getOptions is not a function
Winter combat camp hands-on combat - MySQL database rapid deployment practice lead mouse cloud Xiaobao
Thanos compact component test summary (processing historical data)
随机推荐
js时间获取本周一、周日,判断时间是今天,今天前、后
【机器学习】笔记 4、KNN+交叉验证
Abnormal record-17
Dolphinscheduler集成Flink任务踩坑记录
Binder机制原理
数据库的事务
AVD Pixel_2_API_24 is already running.If that is not the case, delete the files at C:\Users\admi
Oracle和mysql批量查询用户下所有表名和表名注释
Exception record-14
Explore how @ modelandview can forward data and pages through the source code
Abnormal record-16
Dolphinscheduler调度spark任务踩坑记录
When switch case, concatenate the error case and if of the conventional judgment expression and use L
组件化学习
Dolphinscheduler配置Datax踩坑记录
iTOP4412内核反复重启
Oracle RAC数据库实例启动异常问题分析IPC Send timeout
Thanos compact component test summary (processing historical data)
B站用户视频观看记录的存储方案
oracle杀死正在执行的sql