title: Call a function in java from C outside of a JNI function (Android)?
body: <p>I'm trying to call a Java function from my C code using the JNI in Android, but I'm in a somewhat awkward situation. </p>
  
  <p>My C code is being executed outside of a JNI function in a callback that is passed to a library. </p>
  
  <p>Here is an example of the java code</p>
  
  <pre><code>package com.my.java.package;
  
  class MyClass {
      public function handleData(byte[] data) {
          doSomethingWithThisData(data);
      }
  }
  </code></pre>
  
  <p>Here is an example of the C code</p>
  
  <pre><code>void handleData(uint8_t *data, size_t len) {
      // I need to call handleData in my java
      // class instance from here, but i have
      // no access to a JNIEnv here.
  
      // I don't think I can create one, since 
      // it has to be the same object that's 
      // sending JNI calls elsewhere.
  }
  
  . . . 
  
  myCLibInstance.callback = handleData;
  </code></pre>
  
  <p>Now whenever the C Lib does what it needs to do, it will trigger the callback. But I have no way to send it back to the java class to handle the data. </p>