-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在Fragment里navigate 加reqeust code,onActivityResult只能在Activity里回调,这是个bug吧? #885
Comments
不好使啊, |
@XinYiWorld 没用的兄弟,即使是用fragment的getContext,拿到的还是这个fragment所在的Activity |
要想再fragment、里面回调,必须用fragment host的startactivityfroresult而不是context的,所以必须用fragment.startactivityforresult. 你可以用Androidx的result api来做,非常方便 |
@JeckChou 对的,必须是Fragment.startActivityForResult才可以,所以ARouter的navigation是不是应该要加个fragment的重载? |
result api刚出来,ARouter也不支持 |
我是小红帽,不用谢 val postcard = ARouter.getInstance().build(RouterPage.SUBJECT) fun ARouter.fragmentNavigation(fragment: Fragment, postcard: Postcard, requestCode: Int) { |
谢谢了,ARouter的源码有些凌乱,所以已经搞了个Router,感觉用着还不错。 |
@herdin723 你这样,那些拦截器什么的,绿色通道什么的都用不上吧 |
if (currentContext instanceof Activity) { ActivityCompat.startActivityForResult((Activity) currentContext, intent, requestCode, postcard.getOptionsBundle()); } else { logger.warning(Consts.TAG, "Must use [navigation(activity, ...)] to support [startActivityForResult]"); }
这个是ARouter的源码,如果在Fragment startActivity reqeust code,那么只能传递getActivity(),requestCode,onActivityResult的回调只会走Activity,不会走Fragment的onActivityResult的回调。正确的应该是navigate传fragment的getContext,用context去跳转。
The text was updated successfully, but these errors were encountered: