Created
December 14, 2015 14:39
-
-
Save maple-nishiyama/990a4830f5865a0f1466 to your computer and use it in GitHub Desktop.
Android JNI で C/C++ のポインタを Java に渡す。(Java 側のソース)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.ndkpointer; | |
import android.app.Activity; | |
import android.os.Bundle; | |
public class MainActivity extends Activity { | |
static { | |
System.loadLibrary("NdkPointer"); | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
nativeMethod(); | |
} | |
public static native void nativeMethod(); | |
public static native void callback(long cppPointer); | |
public static void asyncProc(final long cppPointer) { | |
Thread t = new Thread(new Runnable() { | |
@Override | |
public void run() { | |
// 時間のかかる処理 | |
try { | |
Thread.sleep(3000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
callback(cppPointer); | |
} | |
}); | |
t.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment