Git Product home page Git Product logo

Comments (5)

weigao123 avatar weigao123 commented on August 31, 2024

可以,这里不适合用重定向,可以考虑下面这种方式

@interceptor(global = true)
public class GlobalInterceptor implements IRouterInterceptor {

public GlobalInterceptor() {
    RouterLogger.getAppLogger().d("GlobalInterceptor create");
}

@Override
public void handle(@NonNull final Request request) {
    
    switch (request.getUri().toString()) {
        case "/activity/page1":
        case "/activity/page2":
            DRouter.build("/login")
                    .start(request.getContext(), new RouterCallback.ActivityCallback() {
                        @Override
                        public void onActivityResult(int resultCode, @Nullable Intent data) {
                            request.getInterceptor().onContinue();
                        }
                    });
            return;
    }
    request.getInterceptor().onContinue();
}

}

from drouter.

xujhin-dev avatar xujhin-dev commented on August 31, 2024

从activity中跳转是没有问题,但是在fragment 中使用 并不会回调

from drouter.

weigao123 avatar weigao123 commented on August 31, 2024

不会回调是什么意思,怎么使用的?

from drouter.

XuJhin avatar XuJhin commented on August 31, 2024

我在fragment中使用DRouter.build(uri).start()调用路由跳转。

`@Interceptor(
global = true
)
class LoginInterceptor : IRouterInterceptor {
companion object {
const val LOGIN_QUERY = "needLogin"
const val LOGIN_URl = "https://app.ink.net/login"
}

override fun handle(request: Request) {
    if (checkNeedLogin(request)) {
        DRouter.build(LOGIN_URl)
            .start(request.context, object : RouterCallback.ActivityCallback() {
                override fun onActivityResult(resultCode: Int, @Nullable data: Intent?) {
                    Log.d("result,", "${resultCode}")
                    request.interceptor.onContinue()
                }
            })
        return
    } else {
        request.interceptor.onContinue()
    }
}

private fun checkNeedLogin(request: Request): Boolean {
    val needLogin = request.uri.getQueryParameter(LOGIN_QUERY)
    if (needLogin.isNullOrEmpty()) {
        return false
    }
    return needLogin.equals("true", false)
}

}`
因为拦截器的原因,所以会进入拦截器。最终也正确在拦截器的作用下进入了登录页,但是我在登录页成功登录以后,并不会执行onActivityResult()方法。
从activity中使用DcRouter.start()就能正常执行

from drouter.

weigao123 avatar weigao123 commented on August 31, 2024

确认一下context是用的Activity吗?代码的设计即便Activity被回收了也会回调回来的,onActivityResult 里 Log.d("result,", "${resultCode}") 这句执行了吗?

抱歉回复晚了,最近业务有调整,后续可以微信直接联系哈

from drouter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.