- Home /
Faster way to Pass data from C# to Java (Android)
Using AndroidJavaClass.CallStatic("func", new object[] { data } );
I can pass data from Unity to a parent Android Activity... however this is slow.
It currently takes 48ms for every call I send, and I want to be calling 30-60 times per second. I am sending a large byte[] Is there a quicker option?
I have started looking at different JVM Serializers but am not sure if that is the right track?
How does object serialisation work with the AndroidJavaClass? How is the data serialised and sent between languages?
Answer by jdean300 · Feb 10, 2017 at 08:18 PM
Doing it this way has to use Reflection, which is never going to work if you are calling it every frame. I don't think the data serialization is your bottleneck.
I think your best bet is to look into pipes. I have never done this on Android, but I have had C# and Java processes communicating through these before and it works well enough. Read this for more info.
You could potentially use a socket, but I would expect that to be slower then pipes (although maybe easier to setup).
Thankyou! Will try it out and report back any speed increase!
This was significantly faster, I will try and extract an example from my codebase and post it for any future visitors, as there isn't a complete example online for doing this on android between Unity/Java. Thankyou!
Hi! Could you post the code of how you did this? I'm having a very similar problem and it would be very useful to see how you solved it!
Thanks!
Hi, I am running into this exact same issue, if you could help with a working implementation that would be amazing