目前的方法是在写arouter build目标的时候传入一个回调监听方法,里面可以在路由被拦截的时候做出一些回应,然后拦截器里只是决定是否拦截,想看看有没有可以在拦截器里直接处理一些问题的方法 ,实在没有也可以把一些处理完了再返回一些flag
照理来说是有post.setPath是可以改变目标页面的
改之前的postcard
Postcard
{uri=/v3/ui/X6ApprovalClientActivity,
tag=null,
mBundle=Bundle[{NTeRQWvye18AkPd6G=/v3/ui/X6ApprovalClientActivity}],
flags=0,
timeout=300,
provider=null,
greenChannel=false,
optionsCompat=null,
enterAnim=-1,
exitAnim=-1}
RouteMeta
{type=ACTIVITY,
rawType=null,
destination=class com.edusoho.kuozhi.v3.ui.X6ApprovalClientActivity, path='/v3/ui/X6ApprovalClientActivity',
group='v3',
priority=-1,
extra=-2147483648,
paramsType=null,
name='null'}
实际上已经把path和extra里都改了但是都没有生效跳转,打印了先后的postcard之后改了一下distination才成功
借鉴一下吧
Log.i("qqhh", "拦截器改之前的目标页面:"+postcard.getPath());
Log.i("qqhh", "拦截器改过的目标页面postcard:"+postcard);
Log.i("qqhh", "拦截器改之前的目标页面:"+postcard.getUri());
Log.i("qqhh", "拦截器Extras:"+postcard.getExtras());
postcard.setExtra(5);
postcard.setPath("/kuozhi/qq/toBeMTeacherActivity");
Uri uri = Uri.parse("/v3/ui/mqWebviewActivity");
postcard.setUri(uri);
Bundle bundle = new Bundle(); //得到bundle对象
bundle.putString("NTeRQWvye18AkPd6G", "/kuozhi/qq/toBeMTeacherActivity"); //key-"sff",通过key得到value-"value值"(String型)
postcard.with(bundle);
postcard.withInt("courseId",courseId);
postcard.setDestination(toBeMTeacherActivity.class);
// Bundle bd=[{"NTeRQWvye18AkPd6G":"/v3/ui/X6ApprovalClientActivity"}];
// Bundle[{NTeRQWvye18AkPd6G=/v3/ui/X6ApprovalClientActivity}]
Log.i("qqhh", "拦截器改过的目标页面path:"+postcard.getPath());
Log.i("qqhh", "拦截器改过的目标页面postcard:"+postcard);
Log.i("qqhh", "拦截器改之前的目标页面uri:"+postcard.getUri());
Log.i("qqhh", "拦截器Extras:"+postcard.getExtras());
Log.i("qqhh", "拦截器courseId:"+postcard.getExtras().getInt("courseId"));
打印的log
2022-05-31 23:46:23.819 29201-29201/com.dmdfchina.view I/qqhh: 拦截器改之前的目标页面:/v3/ui/X6ApprovalClientActivity
2022-05-31 23:46:23.820 29201-29201/com.dmdfchina.view I/qqhh: 拦截器改过的目标页面postcard:Postcard{uri=/v3/ui/X6ApprovalClientActivity, tag=null, mBundle=Bundle[{NTeRQWvye18AkPd6G=/v3/ui/X6ApprovalClientActivity}], flags=0, timeout=300, provider=null, greenChannel=false, optionsCompat=null, enterAnim=-1, exitAnim=-1}
RouteMeta{type=ACTIVITY, rawType=null, destination=class com.edusoho.kuozhi.v3.ui.X6ApprovalClientActivity, path='/v3/ui/X6ApprovalClientActivity', group='v3', priority=-1, extra=-2147483648, paramsType=null, name='null'}
2022-05-31 23:46:23.820 29201-29201/com.dmdfchina.view I/qqhh: 拦截器改之前的目标页面:/v3/ui/X6ApprovalClientActivity
2022-05-31 23:46:23.820 29201-29201/com.dmdfchina.view I/qqhh: 拦截器Extras:Bundle[{NTeRQWvye18AkPd6G=/v3/ui/X6ApprovalClientActivity}]
2022-05-31 23:46:23.820 29201-29201/com.dmdfchina.view I/qqhh: 拦截器改过的目标页面path:/kuozhi/qq/toBeMTeacherActivity
2022-05-31 23:46:23.820 29201-29201/com.dmdfchina.view I/qqhh: 拦截器改过的目标页面postcard:Postcard{uri=/v3/ui/mqWebviewActivity, tag=null, mBundle=Bundle[{courseId=1875, NTeRQWvye18AkPd6G=/kuozhi/qq/toBeMTeacherActivity}], flags=0, timeout=300, provider=null, greenChannel=false, optionsCompat=null, enterAnim=-1, exitAnim=-1}
RouteMeta{type=ACTIVITY, rawType=null, destination=class com.edusoho.kuozhi.qq.toBeMTeacherActivity, path='/kuozhi/qq/toBeMTeacherActivity', group='v3', priority=-1, extra=5, paramsType=null, name='null'}
2022-05-31 23:46:23.820 29201-29201/com.dmdfchina.view I/qqhh: 拦截器改之前的目标页面uri:/v3/ui/mqWebviewActivity
2022-05-31 23:46:23.820 29201-29201/com.dmdfchina.view I/qqhh: 拦截器Extras:Bundle[{courseId=1875, NTeRQWvye18AkPd6G=/kuozhi/qq/toBeMTeacherActivity}]
2022-05-31 23:46:23.820 29201-29201/com.dmdfchina.view I/qqhh: 拦截器courseId:1875
https://blog.csdn.net/y1962475006/article/details/83026256
点击按钮后是模块里的firstActivity
转activity之后,看看拦截器里是执行navigation的时候拦截,判断name和age是否为空
之后为空的时候拦截,不为空跳转
arouter提供了拦截器接口和@Interceptor注解,拦截方法在process里
一个用于组件化改造的框架,支持模块间的路由通信和解耦,拦截跳转
记录启动日志的拦截器,之后是在arouter传入参数
在第一个activity里设置安装体制屯result里接收请求代码,响应代码和和intent data,里面处理一下请求代码是123的写法
之后在跳转的navigation里带请求代码
在第二个页面使用setresult方法可以带参返回第一个页面
拦截的方法是在process里,可以设置一下运行exception
postcard.getExtras().getInt(“age”);
postcard.getExtras().getString(“name”);
额外关注一下afterInit方法,返回了拦截服务器的单实例对象