Android组件化开发-----页面路由(ARouter)

平时开发中,我们经常用到页面跳转功能。之前我一直使用Intent过跳转

Intent intent = new Intent(A.this, B.class);
intent.putExtra("key","value");
startActivity(intent);

最近看到有大牛使用ARouter,专门了解一下,弄个简单入门的demo

下面的文字粘自Alibaba Open Source

   A android router middleware that help app navigating to activities and custom services.
  1. 支持直接解析标准URL进行跳转,并自动注入参数到目标页面中
  2. 支持多模块工程使用
  3. 支持添加多个拦截器,自定义拦截顺序
  4. 支持依赖注入,可单独作为依赖注入框架使用
  5. 支持InstantRun
  6. 支持MultiDex(Google方案)
  7. 映射关系按组分类、多级管理,按需初始化
  8. 支持用户指定全局降级与局部降级策略
  9. 页面、拦截器、服务等组件均自动注册到框架
  10. 支持多种方式配置转场动画
  11. 支持获取Fragment
  12. 完全支持Kotlin以及混编(配置见文末 其他#5)

 多个module间解耦,组件化开发,跳转同一管理

使用步骤:

1. 配置build.gradle:

 defaultConfig中添加

//arouter(Android页面路由框架)
javaCompileOptions {
annotationProcessorOptions {
arguments = [ moduleName : project.getName() ]
}
}

dependencies中添加
//arouter(Android页面路由框架)https://github.com/alibaba/ARouter
compile 'com.alibaba:arouter-api:1.2.2'
annotationProcessor 'com.alibaba:arouter-compiler:1.1.3'


2.所有支持路由的页面都要添加注解:
@Route(path=MyARouter.MainActivity)

        

3.在application中初始化SDK:

       

  4.ARouter发起页面跳转

     


Demo链接:https://github.com/HeavenDong/ARouterDemo
alibaba开源有更详细的使用https://github.com/alibaba/arouter
 

  

 
 
原文地址:https://www.cnblogs.com/donghaifeng-2016/p/7642523.html