java - How synchronize in JNI? -


i'm trying develop android app uses accelerometer of device. want read first 5 events of accelerometer , save accelerations, , after stuff on that.

my jni code is:

asensoreventqueue* sensoreventqueue; asensormanager* sensormanager; vector<double> xx, yy, zz;  static int get_sensor_events(int fd, int events, void* data) {     asensorevent event;      while (asensoreventqueue_getevents(sensoreventqueue, &event, 1) > 0) {         //logi("accelerometer x = %f y = %f z=%f t=%lld", event.acceleration.x, event.acceleration.y, event.acceleration.z, event.timestamp);         xx.push_back(event.acceleration.x);         yy.push_back(event.acceleration.y);         zz.push_back(event.acceleration.z);     }     if (xx.size() > 5) {         asensormanager_destroyeventqueue(sensormanager, sensoreventqueue);         return 0;     }     return 1; }  extern "c" {  jniexport jint jnicall java_com_example_sensor_mainactivity_sensor(jnienv *env,jclass clas,jobject activity) {     asensorevent event;     int events, ident;     asensorref accsensor;      logi("sensorvalue() - alooper_forthread()");     alooper* looper;     looper = alooper_forthread();     if(looper == null) looper = alooper_prepare(alooper_prepare_allow_non_callbacks);      sensormanager = asensormanager_getinstance();     accsensor = asensormanager_getdefaultsensor(sensormanager, asensor_type_accelerometer);      sensoreventqueue = asensormanager_createeventqueue(sensormanager, looper, 1, get_sensor_events, null);     asensoreventqueue_enablesensor(sensoreventqueue, accsensor);     //sampling rate: 100hz     int = asensor_getmindelay(accsensor);     logi("min-delay: %d",a);     asensoreventqueue_seteventrate(sensoreventqueue, accsensor, 0);     logi("sensorvalue() - start");      //do stuff of vectors     return 1; }  } 

the problem looper creates background thread. main thread terminates first , after background thread terminates, want stuff in main thread after looper thread terminates.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -