2
0
mirror of synced 2025-02-23 14:58:12 +00:00
mobile/app/Go.java
Hyang-Ah (Hana) Kim 601608a0e0 bind/java: use the class loader cached during JNI_OnLoad call.
This allows the application class loader to be used when
the bind/java package or other part of JNI dynamically
loads java classes from a non-Java thread.

http://developer.android.com/training/articles/perf-jni.html#faq_FindClass

Fixes golang/go#10668.

Change-Id: I44df3a9362617fa6dd26ddf88247e4fdaee7c7e8
Reviewed-on: https://go-review.googlesource.com/9732
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-05-06 03:41:18 +00:00

38 lines
933 B
Java

package go;
import android.content.Context;
import android.os.Looper;
import android.util.Log;
// Go is an entry point for libraries compiled in Go.
// In an app's Application.onCreate, call:
//
// Go.init(getApplicationContext());
//
// When the function returns, it is safe to start calling
// Go code.
public final class Go {
// init loads libgojni.so and starts the runtime.
public static void init(final Context ctx) {
if (Looper.myLooper() != Looper.getMainLooper()) {
Log.wtf("Go", "Go.init must be called from main thread (looper="+Looper.myLooper().toString()+")");
}
if (running) {
return;
}
running = true;
// TODO(crawshaw): context.registerComponentCallbacks for runtime.GC
System.loadLibrary("gojni");
Go.run(ctx);
new Thread("GoReceive") {
public void run() { Seq.receive(); }
}.start();
}
private static boolean running = false;
private static native void run(Context ctx);
}