'Passing data to multiple fragments

I have 3 fragments and want to send same data to 2 of them. I wrote the below code for the first destination:

 val bundle = Bundle()
 bundle.putString("key",mainText.toString())
 bundle.putString("imageKey",mainImage.toString())
 val fragment = NextFragment()
 fragment.arguments = bundle
 fragmentManager?.beginTransaction()?.replace(R.id.navController,fragment)?.commit()

Then, get the data with

    var args = this.arguments
    var passedText = args?.get("key")
    var passedImage = args?.get("imageKey")

However, for the second destination fragment, I cannot get the data. I used the same bundle as above, tried to create a new one but none of them works. I also tried to pass data using the destination

Home Fragment -> Fragment 1 -> Fragment 2

and

Home Fragment -> Fragment 2

What may be the problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source