Restarting in Android NDK is annoying. Any static data that you use because it reuses this process, so you need to manually reset something that will be invalid on a new start (for example, any OpenGL objects or vertex buffer objects). This gives you a new Java thread and a new Java application and other objects, so any cached global object references that will be new in a new instance of your application should also be cleared.
So, the strategy that I am using is twofold: minimize restart and nuke everything on restart.
You minimize reloads by handling configChanges in the application, as stated in the answer to your question. Then opening the keyboard or turning it off does not restart the application, which should be for any application with a non-trivial launch time.
And when I found that a new instance of my application started, I release all critical data from the old instance at that moment, including the release of any Java objects that I held on to via NewGlobalRef. I tried to minimize static data, but a few inevitable places where I deal with static objects, I clear them when I detect the start of a new instance.
Old threads should go away when there are no more prominent references to them (i.e., after you have released all your NewGlobalRef objects).
SomeCallMeTim
source share