当前位置:网站首页>Component based learning (3) path and group annotations in arouter
Component based learning (3) path and group annotations in arouter
2022-04-23 07:12:00 【Drink dichlorvos alone】
It's not right here ARouter A comprehensive analysis of , But the Group and Path Abstract your thoughts to understand
1. introduce Group and Path
I also mentioned in the last article ,Group
It's the group ,Path
Is the specific class in the group . stay ARouter
Of api Module , Targeted Group
and Path
The interface of ARouterGroup
and ARouterPath
. as follows ( Here's just an example , There is not necessarily an interface with the same name , But the mind is the same )
public interface ARouterGroup {
Map<String, Class<? extends ARouterPath>> getGroupMap();
}
ARouterGroup
Interface :
There is oneMap
aggregate ,key
, Is the name of each group , such asapp
,common
wait .value
Is the detail class corresponding to each group name . In fact, it is realizedARouterPath
The class of the interface .ARouterPath
Interface :
public interface ARouterPath {
Map<String, RouterBean> getPathMap();
}
there key
Namely Path
,value
Even with Path
Corresponding , By RouterBean
Encapsulated class
object . such as key
yes /app/MainActivity
,value
Namely RouterBean<MainActivity.class>
RouterBean
That's it , Which is framed Class object . It can be understood that pairs Class Encapsulation of objects
2.Path and Group How it works
Be careful : To have a first Path
The interface of ARouterPath
, There's more Group
The interface of ARouterGroup
, because Group
To traverse, use Path
Speaking of this , Maybe it's still right ARouterGroup
Interface ,ARouterPath
Not familiar with the interface . I'm here to bring the concrete effect , It's easy to understand
When implementing , It is using JavaPoet When generating class files
① First generate , Realized ARouterPath
The class of the interface . Different group
There are different implementation classes . such as app The group corresponds to one ARouterPath
Implementation class of , There's one in there, too Map aggregate ,key
It can be app
All in the group Path
,value
Even with Path
Corresponding RouterBean
.
② Then generate and implement ARouterGroup
The class of the interface . This class is also a group corresponding to one , It is equivalent to a module corresponding to a routing table .key
Just different groups ,value
That's what different groups correspond to ARouterPath
Implementation class of .
If there are only two business modules at present , namely order and personal, be
① Implementation of generation ARouterPath
The specific code implementation of the interface class is shown in the figure
order
Module generated , InsideMap
The collection is stored order All modules path
personal
Module generated
② Implementation of generation ARouterGroup
The specific code implementation of the interface class is shown in the figure
order
Plate generated , It stores the corresponding implementation of all possible modulesARouterPath
Of Class objectpersonal
Plate generated
ARouterManager
Is a global , It's used to cache ARouter$$Group
and ARouter$$Path
Of
When communication is needed , such as order
Module to personal
Module communication , I think we need to find the overall situation ARouterManager
Is there a cache in it ARouter$$Group$$personal
, If there is , Just use the cache directly ARouter$$Group$$personal
, find ARouter$$Path$$personal.class
, And then get the target class RouterBean
object , That is, we get the of the target class class
object , communicate , without , Just compile the generated ARouter$$Group$$personal
Classes and ARouter$$Path$$personal
Add to ARouterManager
Inside ( namely Lazy loading ), Then complete the jump
The code description is like this :
ARouter$$Group$$personal.getGroupMap().get("personal").get("targetClass")
ARouter Parameter transfer of , It's a similar idea , and ButterKnife It's very similar . Is to annotate the parameter definition to be passed , Then, when compiling, generate the class file of a specific class , The purpose of this class file is to use Bundle
, Assign values to these parameters of the corresponding class
What I understand Path and Group That's how it works . The specific method of generating these class files JavaPoet Code , I haven't studied in detail yet , Learn when you need it later , Now master your thoughts .
版权声明
本文为[Drink dichlorvos alone]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230606380247.html
边栏推荐
猜你喜欢
常用UI控件简写名
./gradlew: Permission denied
Android清除应用缓存
【2021年新书推荐】Effortless App Development with Oracle Visual Builder
Cause: dx. jar is missing
组件化学习(2)Arouter原理学习
oracle通过触发器和序列来定义自增主键,并且设置定时任务每秒钟插入一条数据到目标表
基于BottomNavigationView实现底部导航栏
Oracle Job定时任务的使用详解
【2021年新书推荐】Professional Azure SQL Managed Database Administration
随机推荐
Abnormal record-19
SQL中 with函数的详解与用法
oracle杀死正在执行的sql
useReducer基本用法
org. xml. sax. SAXParseException; lineNumber: 141; columnNumber: 252; cvc-complex-type. 2.4. a: Found element 'B
Using stack to realize queue out and in
MySQL笔记5_操作数据
Itop4412 HDMI display (4.0.3_r1)
【2021年新书推荐】Professional Azure SQL Managed Database Administration
[exynos4412] [itop4412] [android-k] add product options
Using queue to realize stack
oracle视图相关
iTOP4412 SurfaceFlinger(4.0.3_r1)
mysql和pgsql时间相关操作
Android room database quick start
三种实现ImageView以自身中心为原点旋转的方法
【2021年新书推荐】Learn WinUI 3.0
webView因证书问题显示一片空白
利用队列实现栈
Information:2021/9/29 10:01 - Build completed with 1 error and 0 warnings in 11s 30ms Error异常处理