My app is written 99% in C with just some Java helper functions for things not available in the NDK. As a file chooser I'm using a ListActivity that I'm starting like this from the Java side:
Intent myIntent = new Intent(this, FileChooser.class);
startActivity(myIntent);
While this ListActivity is running, my NDK thread waits for the user to select a file and close the ListActivity using
ALooper_pollAll();
Whenever an event wakes up my NDK thread, I'm calling the Java side using JNI to check a flag that indicates whether the ListActivity is still open or has been closed by the user. In my ListActivity's onDestroy() method I have the following code:
@Override
protected void onDestroy() {
super.onDestroy();
if(isFinishing()) listActivityDone = true;
}
Now my problem is that when the user presses the BACK button in the ListActivity, my NDK thread gets woken up correctly but unfortunately, onDestroy() is called after my NDK thread has been woken up, thus my NDK thread does not get the correct value of the flag "listActivityDone". When my NDK thread is woken up, "listActivityDone" is still FALSE because onDestroy() is called immediately after my NDK thread gets woken up.
So what I need to do to solve this problem is wake up the NDK thread once again after having set the flag "listActivityDone" to TRUE. Does anybody know how this can be achieved?
Of course, I could call a C function from Java and then call ALooper_wake() but I'm almost sure that there is a nicer version to wake up the NDK thread from the Java side. Any ideas?
Thanks for your help!