Skip to content
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

Closed
XinYiWorld opened this issue Dec 24, 2020 · 8 comments

Comments

@XinYiWorld
Copy link

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去跳转。

@renwavewave
Copy link

不好使啊,

@wangrunxiang
Copy link

@XinYiWorld 没用的兄弟,即使是用fragment的getContext,拿到的还是这个fragment所在的Activity

@JeckChou
Copy link

要想再fragment、里面回调,必须用fragment host的startactivityfroresult而不是context的,所以必须用fragment.startactivityforresult. 你可以用Androidx的result api来做,非常方便

@wangrunxiang
Copy link

@JeckChou 对的,必须是Fragment.startActivityForResult才可以,所以ARouter的navigation是不是应该要加个fragment的重载?

@wangrunxiang
Copy link

result api刚出来,ARouter也不支持

@herdin723
Copy link

herdin723 commented Oct 22, 2021

我是小红帽,不用谢

val postcard = ARouter.getInstance().build(RouterPage.SUBJECT)
ARouter.getInstance().fragmentNavigation(this, postcard,1000)

fun ARouter.fragmentNavigation(fragment: Fragment, postcard: Postcard, requestCode: Int) {
LogisticsCenter.completion(postcard)
val intent = Intent(fragment.activity,postcard.destination)
intent.putExtras(postcard.extras)
fragment.startActivityForResult(intent, requestCode)
}

@XinYiWorld
Copy link
Author

谢谢了,ARouter的源码有些凌乱,所以已经搞了个Router,感觉用着还不错。

@wangrunxiang
Copy link

@herdin723 你这样,那些拦截器什么的,绿色通道什么的都用不上吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants