Android. How to share result from one fragment to another with fragment result api?

29 Views Asked by At

I'm trying to share result from one fragment to another with fragment result api. Here is my fragment structure: Activity - container contains: FragmentA, FragmentB, FragmentC.

At the same time FragmentA also contains FragmentA1 (FragmentA.childFragmentManager.fragments = FragmentA1)

And now I need to share result from FragmentC to FragmentA1.

My code inside FragmentC:

 setFragmentResult(
                                requestKey = REQUEST_KEY,
                                result = bundleOf(
                                    RESULT_CATEGORY_ID to it.id,
                                ),
                            )

My code inside fragmentA1 inside onCreate:

 setFragmentResultListener(
            FragmentC.REQUEST_KEY,
        ) { _, bundle ->
          // handle result 
        }

The problem is that this handler is never called and I don't get any result.

Is it possible to fix this? Or, with such a structure of fragments, it will not be possible to share the result with fragment result api.

0

There are 0 best solutions below