使用ARouter进行Android模块化开发,2021年Android春招面试经历

本文介绍了如何使用ARouter进行Android模块化开发,包括初始化SDK、发起路由操作、设置拦截器和降级策略。同时,分享了2021年Android春招面试的相关经验,强调了ARouter在处理登录拦截和降级方案中的作用。
摘要由CSDN通过智能技术生成
初始化SDK

if (isDebug()) { // 这两行必须写在init之前,否则这些配置在init过程中将无效
ARouter.openLog(); // 打印日志
ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
}
ARouter.init(mApplication); // 尽可能早,推荐在Application中初始化

发起路由操作

所谓发起路由操作,就是指触发路由的操作,例如:

// 1. 应用内简单的跳转(通过URL跳转在’进阶用法’中)
ARouter.getInstance().build("/test/activity").navigation();

// 2. 跳转并携带参数
ARouter.getInstance().build("/test/1")
.withLong(“key1”, 666L)
.withString(“key3”, “888”)
.withObject(“key4”, new Test(“Jack”, “Rose”))
.navigation();

如果要接受传递处理的数据,可以使用下面的方式:

@Route(path = MainRoutePath.MAIN_ACTIVITY)
public class MainActivity extends BaseActivity {

/**

  • 接收参数
    */
    @Autowired(name = “name”)
    public String name;
    @Autowired(name = “age”)
    public int age;

    }
拦截器

// A more classic application is to handle login events during a jump so that there is no need to repeat the login check on the target page.
// Interceptors will be executed between jumps, multiple interceptors will be executed in order of priority
@Interceptor(priority = 8, name = “test interceptor”

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值