This is the way I implemented this in one of my apps. I didn't use a random file name, but it works well. You can pass a small amount of data as a parameter but the length is limited, if you don't know how much data will need to be passed, it is easier and safer to use a file and pass the path to it.
I also used the same filename to send data back when required.