fragmentResultListener可以在多个片段中与同一请求密钥一起使用吗?
我有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您用哪种方法设置片段结果侦听器?也许它正在使用不同的
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 theFragmentManager
relies on a map to set the resultsMap<String, Bundle>
which does not allow for duplicate keys.