Search code examples
androidandroid-fragmentsandroid-activityinteraction

Send data from Activity to Fragment already created


I only have found information about how to create a Fragment sending some data to it, but only in its instantiation with the constructor.

But I want to know if it is possible to send some data (for instance, two Double objects) to a Fragment from an Activity without having to create a new instance of the Fragment.

A Fragment that has been previously created.


Solution

  • Just add a method in Fragment which you want to receive arguments, then invoke the method in Activity.

    Activity's Code:

    Activity's Code

    Fragment's Code:

    Fragment's Code