I have a thread in my native Code (c++) and this thread calls a callback function in java with a passed integer in agument. The callback function in java should modify this integer and returns true or false. The native code sould work with the new (modified) integer.
例:
C-Code:
doSomething()
{
int id = 5;
callback_fct(&id)
}
callback_fct(int* id)
{
jclass integerClass = (env)->FindClass("java/lang/Integer");
jmethodID midConstructor = (env)->GetMethodID(integerClass, "<init>", "(I)V");
jmethodID midIntValue = (env)->GetMethodID(integerClass, "intValue", "()I");
jobject integerObject = (env)->NewObject(integerClass, midConstructor, *id);
//id should be 5
int res = env->CallIntMethod(appl_object, mid, integerObject);
*id= env->CallIntMethod(integerObject, midIntValue);
//id should be 99 now
}
Java-Code:
private int callback( Integer ID)
{
Log.i("JavaWrapper", "callback");
Log.i("JavaWrapper", "Old ID: " + ID); //should be 5
ID = 99;
Log.i("JavaWrapper", "New ID: " + ID); //should be 99
return 0;
}
谁能给我一个简短的例子?
Thanks