Android JNI: pass std::string to Java and back to C++
<p>I have a relative large size std::string. And I want to pass it to Java without copying. And then pass back to another JNI lib. What is the best approach?</p>

<pre><code>jlong some_jni_call() {
  string str = createLargeString(); // say this is from 3rd lib only returns string
  string* strInHeap = new string(str); // this should just increase the reference count?
  jlong handle = (long)strInHeap;
  return handle;
}
</code></pre>

<p>Then I can pass back to JNI: </p>

<pre><code>void use_string(jlong handle) {
  string* str = (string*)handle;
  // use the str...
  delete str; // doesn't look so nice, since people can forget to delete
}
</code></pre>

<p>Is this a good approach?</p>