在处理需求时,看到项目中某个功能用到了ARouter的拦截器来判断登录状态 ,没登录就会跳回登录页,但是interceptor的process()中发现异常情况:
postcard.setTag("登录已失效,请重新登录");
postcard.setExtra(666);
callback.onContinue(postcard);
和正常流程:
callback.onContinue(postcard);
都是调的onContinue,一开始就很迷惑还以为代码出问题了,为啥onContinue还是会走到Navigationcallback的onInterrupt进行了拦截呢?我感觉应该会正常跳转走到onArrival了啊,使用ARouter的代码如下:
ARouter.getInstance()
.build("/message/live")
.withString("roomId", roomId)
.navigation(mContext, new NavCallback() {
@Override
public void onArrival(Postcard postcard) {
}
@Override
public void onInterrupt(Postcard postcard) {
jumpLoginPage(postcard);
}
});
顺着源码走了一下,终于搞明白了:
public Object navigation(Context context, NavigationCallback callback) {
return ARouter.getInstance().navigation(context, this, -1, callback);
}
protected Object navigation(final Context context, final Postcard postcard, final int requestCode, final NavigationCallback callback) {
try {
LogisticsCenter.completion(postcard);
} catch (NoRouteFoundException ex) {
logger.warning(Consts.TAG, ex.getMessage());
if (debuggable()) { // Show friendly tips for user.
Toast.makeText(mContext, "There's no route matched!\n" +
" Path = [" + postcard.getPath() + "]\n" +
" Group &#