先名词解释,路由信息:寻找对象的依据。
RouteMeta包含基本的路由信息,是路由信息的容器,Postcard也是,因为Postcard 继承了RouteMeta。
RouteMeta对象是在自动生成的类里面生成的,这是能包含路由信息的原因。第一篇已经讲到过。
Postcard更多的作用是:完成寻找对象前的准备,以及跳转Activity前的参数准备。
RouteMeta
private RouteType type; // Type of route
private Element rawType; // Raw type of route
private Class<?> destination; // Destination
private String path; // Path of route
private String group; // Group of route
private int priority = -1; // The smaller the number, the higher the priority, 拦截器的优先级。
private int extra; // Extra data
private Map<String, Integer> paramsType; // Param type
private String name;
private Map<String, Autowired> injectConfig; // Cache inject config.
- paramsType, 这个已经没有用了, 已经用injcetConfig替代。可能为了适配老版本,依旧保留着。
- injcetConfig, injcetConfig是加了@AutoWired的属性注解列表。跳转时传递的参数,在跳转目的地会赋值好。
Map<String, Autowired> injectConfig = new HashMap<>();
for (Element field : element.getEnclosedElements()) {
if (field.getKind().isField() && field.getAnnotation(Autowired.class) != null && !types.isSubtype(field.asType(), iProvider)) { // It must be field, then it has annotation, but it not be provider.
Autowired paramConfig = field.getAnnotation(Autowired.class);
String injectName = StringUtils.isEmpty(paramConfig.name()) ? field.getSimpleName().toString() : paramConfig.name();
paramsType.put(injectName, typeUtils.typeExchange(field));
injectConfig.put(injectName, paramConfig);
}
Postcard
private Uri uri;
private Object tag; // A tag prepare for some thing wrong. 在拦截器里有用到。保存了一些错误信息
private Bundle mBundle; // Data to transform。用于给Activity或fragment传递参数
private int flags = -1; // Flags of route. 是Activity的启动模式, 比如,Intent.FLAG_ACTIVITY_NEW_TASK
private int timeout = 300; // Navigation timeout, TimeUnit.Second 在拦截器阻塞执行时间的最长时间。超时后,只在后面默默执行,不再卡Naviagtion().
private IProvider provider; // It will be set value, if this postcard was provider.
private boolean greenChannel; //针对拦截器, 设置true后,不再执行拦截器。
private SerializationService serializationService; //解析json的方式。实现SerializationService后,可以直接传对象,会转化成json传过去。没啥用的吧
private String action; // Intent action, intent.setAction(action); 跳转Activity时会用到。
private Bundle optionsCompat; // The transition animation of activity
private int enterAnim = -1; //activity打开的动画资源
private int exitAnim = -1;//activity关闭的动画资源
- 还有一个withXXXXX()方法, 都是为了封装mBundle。
- Navigation()方法中,最后还是调用了_ARouter类的Navigation()方法。