I originally posted here (include the code): Weird: can not change the value of Integer in jni
To pass multiple value from jni to java, I pass 2 Integer reference to jni/c, and use SetIntField() to modify the object.
Unfortunately, the 2 value are the same. Lawrence D'Oliveiro explains Integer is not mutable, so we cant change it. I don't know why.
As a workaround, I created my own Integer class:
public class MyInteger {
int value;
public MyInteger(int v) {
value = v;
}
}
And pass object of this type to jni:
native int do_something(MyInteger p1, MyInteger p2);
It works. I'm curious why Integer doesn't work. Thanks all.