Q:

Android NDK JNI shared variable is it possible?

I would like to update progress of JNI method to Progress Bar. The simplest way I can think of without creating multiple worker threads would be to have shared variable in ProgressBar activity and then I would just update the shared variable in my JNI method if I get the correct pointer to the address. Is it possible? Or would I have to think of something else?
visible
static long int _PROGRESS = 0; 

I would like to access this variable from native method call let's say
JNI_EXPORT java_com_example(env, jobject......){
for loop{
   //do something
  _PROGRESS++; }}

how can I best make a pointer to the shared variable? Or do I have to return everytime an update occurs, I would like to avoid this given JNI Call overheads.

A:

It needs to be a class static variable, as per the Java rules. There are no variables in global scope in Java.
To update one of those from the C side, use JNIEnv::SetStaticLongField(). To read the current value, use GetStaticLongField(). There's no direct variable access via JNI.
Note that long int is not a valid datatype in Java. long is. And it correponds to jlong on the C side, which is not the same as C long.

