Search Unity

passing arrays back to c# from JAVA using AndroidJavaProxy

Discussion in 'Android' started by blainebell, Aug 11, 2017.

  1. blainebell

    blainebell

    Joined:
    Jun 10, 2016
    Posts:
    28
    It seems like the default behavior of the function AndroidJavaProxy.Invoke() does not support arrays (at least of primitive JAVA variable types. (I am using 2017.1) I can retrieve the array (e.g., int[]) from within the Invoke() by using:

    override public AndroidJavaObject Invoke(string methodName, AndroidJavaObject [] javaArgs){
    AndroidJavaObject arg1 = javaArgs [0];
    int [] arrcopy = arg1.Call<int[]> ("clone", new object[0]);
    }

    However, this seems to require calling the clone() function, which copies the JAVA array. Is there a way to avoid this excessive copy? One way I could think of is to use a dummy class as the argument that holds the array in a member variable, then the Invoke() would call the get function that simply returns the array. Is there an easier way of converting the AndroidJavaObject directly to a c# array?

    Thanks in advance,

    Blaine
     
  2. blainebell

    blainebell

    Joined:
    Jun 10, 2016
    Posts:
    28
    Does anyone at Unity know anything about this? I know there is a workaround, but it would be good if you could point me to some documentation that shows how to do this. Thanks, Blaine