We are developing an OpenGL game on android using the NativeActivity class. So far everything went OK, but now we need to access some functionality that only seems to be availab
Ech, I've been staring at the code for couple of hours and didn't see it. Then left the desk, came back and there it was:
Instead of these two lines
float xdpi = jni->GetFloatField(displayMetricsClass, xdpi_id);
int height = jni->GetIntField(displayMetricsClass, height_id);
I should have used:
float xdpi = jni->GetFloatField(displayMetrics, xdpi_id);
int height = jni->GetIntField(displayMetrics, height_id);
Doh :)
(at least it can serve as an example if someone wants to get DPI the hard way :) )
First off, I must note that I'm not very good with JNI :)
That said, I suspect the problem would be that the displayMetrics
variable must be made a global reference with
displayMetrics = jni->NewGlobalRef(displayMetrics);
or something like that. Remember to unref it with DeleteGlobalRef
. LocalRef might work too...
But if I were to go about solving this problem, I'd wrap the whole thing in a java function and just call that from native and let the java side do most of the function calling - there's also less hopping the java-native fence involved.