title: Android - JNI NewObject() does not save values when passing it to Java
body: <p>I am using native code to create an object which I then pass as an argument to a method I call.
  Nothing appears to go wrong in native code, but when I get the call in Java, the object seems to have nulled values. </p>
  
  <p>Here's the code of the java object I create in native:</p>
  
  <pre><code>package org.test;
  import java.util.ArrayList;
  
  public class JNITeam {
      public int mTeamID;
      public String mTeamName;
      private ArrayList&lt;String&gt; mMembers;
  
      public JNITeam(int id, String name) {
          mTeamID = id;
          mTeamName = name;
      }
  
      public void addMember(String name) {
          mMembers.add(name);
      }
  
  }
  </code></pre>
  
  <p>Here's the native code used to create an instance of the class and pass it up to the Java method "onGetTeam", which takes an instance of the above class as a parameter. It is run from a thread created in Native code, hence I have to attach the thread. </p>
  
  <pre><code>JNIEnv* jenv = 0;
              clientHandle-&gt;runningJVM-&gt;AttachCurrentThread(&amp;jenv,0);
              if (!jenv)
                  __android_log_print(ANDROID_LOG_INFO, ANDROID_DEBUG_TAG, "jenv is null");
  
              jclass cls = jenv-&gt;GetObjectClass(clientHandle-&gt;job);
              if (!cls)
                  __android_log_print(ANDROID_LOG_INFO, ANDROID_DEBUG_TAG, "cls is null");
  
              jmethodID constructor = jenv-&gt;GetMethodID(clientHandle-&gt;JNITeamCls, "&lt;init&gt;", "(ILjava/lang/String;)V");
  
              jint teamID = 2;
              jstring js = jenv-&gt;NewStringUTF("test");
  
              jobject dataObject = jenv-&gt;NewObject(clientHandle-&gt;JNITeamCls, constructor, teamID, js);
              if (!dataObject)
                  __android_log_print(ANDROID_LOG_INFO, ANDROID_DEBUG_TAG, "dataobject is null");
  
              if (jenv &amp;&amp; cls &amp;&amp; dataObject) {
                  jmethodID mid = jenv-&gt;GetMethodID(cls,"onGetTeam","(Lorg/test/JNITeam;)V");
                  if (mid) {
                      jenv-&gt;CallVoidMethod(clientHandle-&gt;job,mid);
                  }
                  else {
                      __android_log_print(ANDROID_LOG_INFO, ANDROID_DEBUG_TAG, "mid is null");
                  }
              }
  </code></pre>
  
  <p>I do not want the object to be persistent; I want it to ony be valid during the call to Java, then it can be garbage-collected. However its data fields - that are set in the constructor - are just null when I call it, Why?</p>