0

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!

4

2 回答 2

0

你能处理APP_CMD_TERM_WINDOW正确关闭的命令吗?

于 2013-01-21T15:26:32.583 回答
0

也许你可以将你的标志移到 onPause、onResume:

@Override
protected void onPause() {    
    super.onPause();          
    if(isFinishing()) listActivityDone = true;      
}

@Override
protected void onResume() {    
    super.onResume();          
    if(!isFinishing()) listActivityDone = false;      
}

这样它就被更早地调用了。如果 onPause 不适用于您的特定场景,您也可以考虑将其放入 onStop

于 2013-01-21T15:24:42.567 回答