ARouter源码解析02-加载路由表单
来源:互联网 发布:卸载office2013软件 编辑:程序博客网 时间:2024/06/05 10:00
上篇文章我我们分析到,ARouter在IDE编译阶段,会自动生成一些文件。在这篇文章,我们将分析加载生成文件中的路由表单的过程。
ARouter.init()
ARouter唯一初始化的过程,在ARouter.init()中。
public static void init(Application application) { //... hasInit = _ARouter.init(application); if (hasInit) { _ARouter.afterInit(); } //...}
通过_ARouter.init(),接着调用了LogisticsCenter.init(),从而预先加载所有的路由表单。
public synchronized static void init(Context context, ThreadPoolExecutor tpe) throws HandlerException { // 这些类通过 ARouter-compiler 生成,这个会去扫描包名下所有的ClassName List<String> classFileNames = ClassUtils.getFileNameByPackageName(mContext, ROUTE_ROOT_PAKCAGE); for (String className : classFileNames) { if (className.startsWith(ROUTE_ROOT_PAKCAGE + DOT + SDK_NAME + SEPARATOR + SUFFIX_ROOT)) { // 加载Root Elements 到 Warehouse的groupsIndex 集合中 ((IRouteRoot) (Class.forName(className).getConstructor().newInstance())).loadInto(Warehouse.groupsIndex); } else if (className.startsWith(ROUTE_ROOT_PAKCAGE + DOT + SDK_NAME + SEPARATOR + SUFFIX_INTERCEPTORS)) { // 加载Interceptor Elements 到 Warehouse的interceptorsIndex 集合中 ((IInterceptorGroup) (Class.forName(className).getConstructor().newInstance())).loadInto(Warehouse.interceptorsIndex); } else if (className.startsWith(ROUTE_ROOT_PAKCAGE + DOT + SDK_NAME + SEPARATOR + SUFFIX_PROVIDERS)) { // 加载Provider Elements 到 Warehouse的providersIndex 集合中 ((IProviderGroup) (Class.forName(className).getConstructor().newInstance())).loadInto(Warehouse.providersIndex); } }}
可以看到,这里会先扫描所有的ROUTE_ROOT_PAKCAGE包下的className,然后遍历这些className,从而将IRouteGroup、IProvider、RouteMeta分别加载到Warehouse的相关集合中存储起来,方便之后的调用。
需要注意的是: 这里并没有把路由表单的目标类预先进行加载,只是将他们的class等数据先缓存起来,这么做的好处显而易见,无须再次通过上面的这些方法来获取路由表单。
再来看一眼Warehouse类
class Warehouse { // Cache route and metas static Map<String, Class<? extends IRouteGroup>> groupsIndex = new HashMap<>(); static Map<String, RouteMeta> routes = new HashMap<>(); // Cache provider static Map<Class, IProvider> providers = new HashMap<>(); static Map<String, RouteMeta> providersIndex = new HashMap<>(); //...}
OK,现在路由表单已加载到内存中了,那么,怎么通过这些路由表单,进行路由跳转呢 ? 我们下篇文章来进行分析。
阅读全文
0 0
- ARouter源码解析02-加载路由表单
- 阿里路由框架--ARouter 源码解析之初始化ARouter
- ARouter源码解析03-路由跳转
- 阿里路由框架--ARouter 源码解析之Compiler
- ARouter源码解析06-openDebug
- ARouter源码解析01-编译生成文件
- ARouter源码解析04-interceptor拦截器
- ARouter源码解析05-自动参数注入
- ARouter 依赖注入实现原理(源码解析)
- [源码]ARouter
- 浅谈Android模块化设计(路由框架ARouter源码分析)
- ARouter 拦截器与路由的实现(源码分析)
- ARouter路由框架介绍
- ARouter 路由框架
- ARouter解析一:基本使用及页面注册源码解析
- ARouter Android页面路由框架
- 阿里ARouter源码分析
- (4.2.40)阿里开源路由框架ARouter的源码分析
- Java 8 基础知识
- 浅拷贝类型的危险构造函数
- dubbo注册中心
- MYSQL 在字段里现有内容后面添加字符串
- Linux下安装Google protobuf
- ARouter源码解析02-加载路由表单
- 21th 【动态规划】路面修整
- 微信小程序支付接口调用
- 8访问数据库
- python 高阶函数
- 初学Android的一些布局
- python之字典
- HDU 6005
- InnoDB调优-分区表