標籤:api and 依賴 攔截器 src nbsp 1.2 end tin
平時開發中,我們經常用到頁面跳轉功能。之前我一直使用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.
- 支援直接解析標準URL進行跳轉,並自動注入參數到目標頁面中
- 支援多模組工程使用
- 支援添加多個攔截器,自訂攔截順序
- 支援依賴注入,可單獨作為依賴注入架構使用
- 支援InstantRun
- 支援MultiDex(Google方案)
- 映射關係按組分類、多級管理,按需初始化
- 支援使用者指定全域降級與局部降級策略
- 頁面、攔截器、服務等組件均自動註冊到架構
- 支援多種方式配置轉場動畫
- 支援擷取Fragment
- 完全支援Kotlin以及混編(配置見文末 其他#5)
使用步驟:
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
Android頁面路由架構 —— ARouter