Skip to content

Repository files navigation

Rudolph

Rudolph Android Router Framework(鲁道夫安卓路由框架组件)

LicenseMaven-Central-ReleaseMaven-Central-Snapshot

版本更新记录

调用实例

  • Activity
UserActivityRouter.builder()
.userId(11)
.userName("John")
.transition(R.anim.in_left,R.anim.out_right)
.buildStart(context);
Rudolph.builder("/user")
.userId(11)
.userName("John")
.extra("age",11)
.transition(R.anim.in_left,R.anim.out_right)
.execute(context);
Stringurl="/user?userId=11&userName=John&age=11"Rudolph.builder(url)
.transition(R.anim.in_left,R.anim.out_right)
.execute(context);
  • Fragment
Fragmentfragment=TestFragmentRouter.builder()
.userId(11)
.userName("John")
.execute();
  • Method
Objectresult=Rudolph.builder("/methodRouter")
.build()
.execute(context);
  • Service
ITestServiceservice = TestServiceRouter.builder()
.userId(1)
.userName("Tom")
.execute();
service.showMessage(MainActivity.this,"Hello Provider!");

框架特性

  • 支持组件API模块自动生成
  • 自动生成路由Builder类与服务类的接口层;
  • 加载更快,更稳定,无需插桩与dex扫描;
  • 无需指定模块名,接入更简单;
  • 显式跳转与URL路由地址跳转融为一体,更方便快捷;
  • 通过Builder方式传参,无需手动写参数名,从而减少参数传错和修改带来的Bug隐患;
  • 支持所有Intent的参数类型;
  • 支持Activity 、Fragment、Service、Method四种路由类型
  • 支持Instant Run
  • 支持AndroidX
  • 支持Kotlin

支持路由类型

1、组件引入

1.添加依赖(1.x.x为版本号)

Java:

repositories {
// Rudolph 正式版仓库地址
mavenCentral()
// Rudolph SNAPSHOT版本仓库地址
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
implementation "cn.wzbos.android:rudolph:1.x.x"
annotationProcessor "cn.wzbos.android:rudolph-compiler:1.x.x"
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor(0, 'seconds')
}

Kotlin:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
repositories {
mavenCentral()
}
dependencies {
implementation "cn.wzbos.android:rudolph:1.x.x"
kapt "cn.wzbos.android:rudolph-compiler:1.x.x"
}

2、代码混淆

所需混淆配置都已经打包到组件内,无需新增额外混淆配置

3、初始化

建议放到application中

Rudolph.init(this);

4、拦截器

  • 添加拦截器
Rudolph.addInterceptor(newInterceptor() {
@Overridepublicbooleanintercept(Contextcontext, RouterrouteInfo) {
if ("/test4".equalsIgnoreCase(routeInfo.getRawUrl())) {
Toast.makeText(MyApplication.this, "intercept,path:" + routeInfo.getRawUrl(), Toast.LENGTH_SHORT).show();
returntrue;
}
returnfalse;
}
});
  • 移除拦截器
Rudolph.removeInterceptor(interceptor);

5、设置scheme

设置当前APP的scheme用于支持其他APP程序跳转到当前APP

Rudolph.setScheme("myApp")

scheme值需要于AndroidManifest.xml文件中的值相同,例如下面的scheme为"myApp"

<activityandroid:name=".MainActivity"android:configChanges="keyboardHidden|orientation"android:screenOrientation="portrait">
<intent-filter>
<dataandroid:scheme="myApp" />
<actionandroid:name="android.intent.action.VIEW" />
<categoryandroid:name="android.intent.category.DEFAULT" />
<categoryandroid:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter>
<actionandroid:name="android.intent.action.MAIN" />
<categoryandroid:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

6、bind

给@Extra注解的变量赋值,一般用在Activity的create 或者 Service的init方法内

Rudolph.bind(this)

7、onNewIntent

用于在Activity的onNewIntent生命周期内重新赋值

Rudolph.onNewIntent("myApp")

8、addRoute

添加一条路由记录,一般场景下不需要用,此方法主要是路由表类自行调用

Rudolph.addRoute(newRouteInfo.Builder().routeType(RouteType.ACTIVITY)
.target(KotlinActivity.class)
.path("/kotlin/test")
.tag("")
.extra("userId",int.class)
.extra("userName",String.class).build());

About

Rudolph android router framework(鲁道夫安卓路由组件框架)

Topics

Resources

Stars

24 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages