Ich habe eine MainActivity
, eine Thread(RunJNIThread)
und eine jniClass.c
. Weil JNI
UI
Thread blockiert, verwende ich Thread, um jniClass.cpp
auszuführen. Ich habe Activity
verwendet, um MainActivity.StartJNI()
in Thread aufzurufen, nachdem ich this gefunden habe, die besagt, "Activity
in eine andere object
zu übergeben ist normalerweise eine schlechte Idee".Wie übergebe ich native Methode, um in android zu fädeln?
Also, wie eine native Methode, die in MainActivity
zu Thread
definiert? Nicht mit Activity
.
MainActivity.java
public RunJNIThread thread;
thread = new RunJNIThread(this);
....
static {
System.loadLibrary("jniClass");
}
public native void StartJNI();
...
RunJNIThread.java
private MainActivity mainActivity;
getFrameThread(MainActivity mainActivity){
this.mainActivity = mainActivity; //Not Good
}
public void run(){
while(!Stop){
mainActivity.StartJNI(); //how to replace this with better way
try {
Thread.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
...
Danke, es funktioniert. –