Is it possible to pass data between fragments without changing the current fragment I am on?

Viewed 48

I am currently trying to make an Android Application that connects to a raspberry pi via bluetooth and send data between them. I am able to connect the two devices and send the data, but only on one of the fragments. Is it possible for me to send data from another fragment to my bluetooth one without actually leaving the current fragment I am on? Thank you in advance!

1 Answers

You could create an object and save data there, then, in the 2nd fragment, access to this object and collect the data.

In Kotlin it would be:

object myObj {
    var data = "something"
}

To get it:

(ClassName where the Obj is located).myObj.data
Related