| OLD | NEW |
| (Empty) |
| 1 package go; | |
| 2 | |
| 3 import android.content.Context; | |
| 4 import android.os.Looper; | |
| 5 import android.util.Log; | |
| 6 | |
| 7 // Go is an entry point for libraries compiled in Go. | |
| 8 // In an app's Application.onCreate, call: | |
| 9 // | |
| 10 // Go.init(getApplicationContext()); | |
| 11 // | |
| 12 // When the function returns, it is safe to start calling | |
| 13 // Go code. | |
| 14 public final class Go { | |
| 15 // init loads libgojni.so and starts the runtime. | |
| 16 public static void init(final Context ctx) { | |
| 17 if (Looper.myLooper() != Looper.getMainLooper()) { | |
| 18 Log.wtf("Go", "Go.init must be called from main thread (
looper="+Looper.myLooper().toString()+")"); | |
| 19 } | |
| 20 if (running) { | |
| 21 return; | |
| 22 } | |
| 23 running = true; | |
| 24 | |
| 25 // TODO(crawshaw): context.registerComponentCallbacks for runtim
e.GC | |
| 26 | |
| 27 System.loadLibrary("gojni"); | |
| 28 | |
| 29 new Thread("GoMain") { | |
| 30 public void run() { | |
| 31 Go.run(ctx); | |
| 32 } | |
| 33 }.start(); | |
| 34 | |
| 35 Go.waitForRun(); | |
| 36 | |
| 37 new Thread("GoReceive") { | |
| 38 public void run() { Seq.receive(); } | |
| 39 }.start(); | |
| 40 } | |
| 41 | |
| 42 private static boolean running = false; | |
| 43 | |
| 44 private static native void run(Context ctx); | |
| 45 private static native void waitForRun(); | |
| 46 } | |
| OLD | NEW |