ARouter源码简析系列二:navigation过程

ARouter源码简析系列一:初始化流程

之前讲了初始化流程,现在接着看navigation过程,先来一个使用示例 后面好举例

@Route(path = "/image/imageActivity")
class MainActivity : AppCompatActivity() {
   
   
    @Autowired(name = "tip")
    @JvmField
    var mTip: String? = ""
    override fun onCreate(savedInstanceState: Bundle?) {
   
   
        super.onCreate(savedInstanceState)
        ARouter.getInstance().inject(this)
        setContentView(R.layout.layout_activity_main)
        findViewById<TextView>(R.id.mTvImageModule).setOnClickListener {
   
   
            ARouter.getInstance().build("/login/loginActivity").navigation(this)
        }
    }
}

1.postcard制作过程

postcard何许人也,翻译是明信片,也就是路由信息类,里面存着路由数据uri, 携带参数,路径等等

protected Object navigation(final Context context, final Postcard postcard, final int requestCode, final NavigationCallback callback) {
   
   
        PretreatmentService pretreatmentService = ARouter.getInstance().navigation(PretreatmentService.class);
        if (null != pretreatmentService && !pretreatmentService.onPretreatment(context, postcard)) {
   
   
            // Pretreatment failed, navigation canceled.
            return null;
        }

        // Set context to postcard.
        postcard.setContext(null == context ? mContext : context);

        try {
   
   
            LogisticsCenter.completion(postcard);
        } 
		//省略代码
        return null;
    }

postcard保存了所有跳转类相关信息
1.设置postcard的context
2.调用LogisticsCenter.completion完善postcard信息

2.完善postcard信息

2.1 @Route生成的映射类(方便举例说明)

public class ARouter$$Group$$image implements IRouteGroup {
   
   
  @Override
  public void loadInto(Map<String, RouteMeta> atlas) {
   
   
    atlas.put("/image/imageActivity", RouteMeta.build(RouteType.ACTIVITY, MainActivity.class, "/image/imageactivity", "image", new java.util.HashMap<String, Integer>(){
   
   {
   
   put("tip", 8); }}, -1, -2147483648));
  }
}

2.2 完善postcard过程 稍长 忍一下

  public synchronized static void completion(Postcard postcard) {
   
   
        if (null == postcard) {
   
   
            throw new NoRouteFoundException(TAG + "No postcard!");
        }
		
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值