Arouter讲解4_Core,android应用开发基础答案

LogisticsCenter.completion(postcard);
return (T) postcard.getProvider();
} catch (NoRouteFoundException ex) {
logger.warning(Consts.TAG, ex.getMessage());
return null;
}
}

从Warehouse.providersIndex 的HashMap中根据全限定名得到 RouteMeta

public static Postcard buildProvider(String serviceName) {
RouteMeta meta = Warehouse.providersIndex.get(serviceName);

if (null == meta) {
return null;
} else {
return new Postcard(meta.getPath(), meta.getGroup());
}
}

刚刚new 出来的 Postcard 只含有 path 和Group,还需要对其他信息进行补充。先从 routes 缓存中根据path获取 RouteMeta,如果缓存中没有,可以动态添加。

如果缓存中有了,就把数据填充到 Postcard

public synchronized static void completion(Postcard postcard) {
if (null == postcard) {
throw new NoRouteFoundException(TAG + “No postcard!”);
}

// 先从缓存类找
RouteMeta routeMeta = Warehouse.routes.get(postcard.getPath());

if (null == routeMeta) {
// Maybe its does’t exist, or didn’t load.
// 缓存里没有
// 可以动态添加,但是先要把group添加进来
if (!Warehouse.groupsIndex.containsKey(postcard.getGroup())) {
throw new NoRouteFoundException(TAG + “There is no route match the path [” + postcard.getPath() + “], in group [” + postcard.getGroup() + “]”);
} else {
// Load route and cache it into memory, then delete from metas.
try {
if (ARouter.debuggable()) {
logger.debug(TAG, String.format(Locale.getDefault(), “The group [%s] starts loading, trigger by [%s]”, postcard.getGroup(), postcard.getPath()));
}

// 动态添加
addRouteGroupDynamic(postcard.getGroup(), null);

if (ARouter.debuggable()) {
logger.debug(TAG, String.format(Locale.getDefault(), “The group [%s] has already been loaded, trigger by [%s]”, postcard.getGroup(), postcard.getPath()));
}
} catch (Exception e) {
throw new HandlerException(TAG + “Fatal exception when loading group meta. [” + e.getMessage() + “]”);
}

completion(postcard); // Reload
}
} else {
// 从缓存取数据
postcard.setDestination(routeMeta.getDestination()); // 路
由目标类
postcard.setType(routeMeta.getType()); // 路由的类型 RouteType ,可以是 ACTIVITY、SERVICE、PROVIDER 、CONTENT_PROVIDER、FRAGMENT等
postcard.setPriority(routeMeta.getPriority()); // 权限值
postcard.setExtra(routeMeta.getExtra()); // 额外的信息

Uri rawUri = postcard.getUri();
if (null != rawUri) { // Try to set params into bundle.
Map<String, String> resultMap = TextUtils.splitQueryParameters(rawUri);
Map<String, Integer> paramsType = routeMeta.getParamsType();

if (MapUtils.isNotEmpty(paramsType)) {
// Set value by its type, just for params which annotation by @Param
for (Map.Entry<String, Integer> params : paramsType.entrySet()) {
setValue(postcard,
params.getValue(),
params.getKey(),

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值