All,
I'm aware that by default an activity will be killed and restarted when the screen orientation changes, or a keyboard is slid in or out. (See http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android). My question is, what is the correct way to handle this from a Native code perspective? e.g. if I have a static block loading a native library and my app is restarted, how do I ensure that any memory in the native land is dealt with appropriately? The problem is
When we rotate the device, it looks like a separate Thread pool is created and the old ones are never removed. This means that every time someone turns the device, we have a ton more threads sitting idle and taking up memory
How do I ensure that this doesn't happen? I see from the JNIExample page some notes at the bottom:
[*]Unresolved issues and bugs Even though the example is fully functional, there are a couple unresolved issues remaining, which I was not able to figure out so far. Problems appear when you start the activity, then press the Back button to hide it, and then start it again. In my experience, calls to native functions in such restarted activity will fail spectacularly. callVoid() simply crashes with a segmentation fault, while calls to getNewData() and getDataString() cause JVM to abort with an error, because it is no longer happy with the globally cached object reference. It appears that activity restart somehow invalidates our cached object references, even though they are protected with NewGlobalRef(), and the activity is running within the original JVM (activity restart does not mean that JVM itself is restarted). I don't have a good explanation on why that happens, so if you have any ideas, please let me know.
Has this been solved?