Call to JNI crashes after android service is restarted?
<p>I have an android service that uses a native library via NDK/JNI. The native library is statically loaded/initialized as suggested...</p>

<pre><code>static {
    System.loadLibrary("mylibrary");
    if (!nativeClassInit())
        throw new RuntimeException("native init failed");
}
</code></pre>

<p>Everything works fine until the service is stopped (e.g., from a UI activity where the service may be started/stopped). The problem is when the service is stopped the task has not yet been killed by android and if the user restarts the service the native libraries are not reloaded and a call to a native function causes a crash in the native code?</p>

<p>I tried calling the nativeClassInit() method again after a restart but this doesn't help?
Also, I seen in other posts that unloading the native library is not allowed in Android.</p>
