初始化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”