Reputation: 1209
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?
Upvotes: 1
Views: 610
Reputation: 6314
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.
Upvotes: 0