fragmentResultListener可以在多个片段中与同一请求密钥一起使用吗?

发布于 2025-01-24 05:23:55 字数 283 浏览 2 评论 0原文

我有fragmenta(nav_graph_a),可导航到fragmentB(nav_graph_b)。 fragmentB导航到对话范围,该对话范围调用setFragmentResult(rk_shared)。

问题在于,在这种情况下,fragmentResultListener回调不会在fragmentB中触发。

问题:我可以重复使用相同的请求密钥以在多个片段中注册fragmentResultListener。 显然,我可以使用唯一的请求密钥来解决此问题。但是最好的做法是什么?

I have FragmentA(nav_graph_a), which navigates to FragmentB(nav_graph_b).
FragmentB navigates to a DialogFragment, which call setFragmentResult(RK_SHARED).
Both FragmentA and FragmentB registers a FragmentResultListener with request key RK_SHARED.

The problem is that in this case, the fragmentResultListener callback is not triggered in FragmentB.

Question: can I reuse the same request key to register FragmentResultListener in multiple fragments.
I could obviously solve this by using a unique request key. But what are the best practices?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流星番茄 2025-01-31 05:23:55

您用哪种方法设置片段结果侦听器?也许它正在使用不同的fragmentManager,这就是为什么它没有收到结果的原因。

另外,不确定您是否要在两个片段中接收结果。但是fragmentResult api 不支持这一点。基本上,只有最后一个用该键注册侦听器的人才会被使用,因为fragmentManager依赖于地图设置结果map< string,bundle>允许重复键。

What method you used to set the fragment result listener? Maybe it is using a different FragmentManager and this is the reason why it doesn't receive the result.

Also, not sure if you want to receive the result in both fragments or not. But the FragmentResult API does not support that. Basically, only the last one that registered a listener with that key will be used because the FragmentManager relies on a map to set the results Map<String, Bundle> which does not allow for duplicate keys.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文