title: How to pass a complex structure between C and Java with JNI on Android NDK
body: <p>I have a complex strucutre in the C code on my Android application and I would like to use it in the Java side.
  I've done some research with google and in stackoverflow, so I've created the java class from my C strucutre, but now how to get it in Java.</p>
  
  <p>I've found these informations, about making a pointer in the class and use this on the C side :</p>
  
  <pre><code>Get the field ID : (*env)-&gt;GetFieldID(...)
  Get the pointer : (*env)-&gt;GetLongField(...)
  Set the pointer : (*env)-&gt;SetLongField(...)
  </code></pre>
  
  <p>But I don't understand how it really works ...</p>
  
  <p>Above, you can find what I've done until now ... not so much !
  On the C side :</p>
  
  <pre><code>ComplexStructure Java_com_main_MainActivity_listenUDP(JNIEnv* env, jclass clazz)
  {
      int i,taille;
      ComplexStructure myStruct;    
      taille = -1;    
      taille = recvfrom(socket, &amp;myStruct, sizeof(ComplexStructure ), 0, &amp;rcvAddr, &amp;sizeOfSock);
      if(taille != -1)
      {   
          return myStruct;
      }
      return NULL;
  }
  </code></pre>
  
  <p>And on the Java side :</p>
  
  <pre><code>public void getFromUDP() {
  
      ComplexClass myClass = new ComplexClass();
      myClass = listenUDP();              
  }
  
  @Override
  public void run() {
      initUDP();
      getFromUDP();
  }
  
  
  public static native ComplexClass listenUDP();
  public static native void initUDP();
  public static native void closeUDP();
  
  /** Load jni .so on initialization */
  static {
       System.loadLibrary("native-interface");
  }
  </code></pre>
  
  <p>EDIT : I want to add that my structure is very complex like that :</p>
  
  <pre><code>typedef struct{
    TYPE_A myStructA;
    TYPE_B myStructB;
    TYPE_C myStructC;
    TYPE_D myStructD;
  }ComplexStructure;
  
  typedef struct{
    float rad;
    int size;
    bool isEmpty;
  }TYPE_A;
  
  typedef struct{
    float rad;
    bool isEmpty;
    float color;
    int temp;
  }TYPE_B;
  
  typedef struct{
    int temp;
    float rain;
    bool isEmpty;
  }TYPE_C;
  
  typedef struct{
    float rad;
    int idPerson;
    bool isOnTime;
  }TYPE_D;
  </code></pre>
  
  <p>Even more complex, just an example to show you how it is !</p>