On Mar 13, 10:22 pm, Dianne Hackborn <
hack...@android.com> wrote:
> On Sun, Mar 13, 2011 at 1:20 PM, MatthiasM
> <
melcher.matth...@googlemail.com>wrote:
>
> > Thanks. Well, if it gets terminated in the background, I do get the
> > onDestroy() call and all is fine.
>
> onDestroy() is not called when an app is terminated in the background; it is
> called when an activity is finished.
OK, thanks. It doesn't seem to get called here. OnStop, onResume, and
all the other ones in my app do get called as expected, but I also
don't have a way to finish the main Activity.
> > But when I am in the "Application Info" panel and click "Force Stop",
> > or when I am in the task manager and click "End", I don't get a
> > message whatsoever. In a purely native application, even when
> > crashing, it would decrement the usage counter of the dynamically
> > linked library and call the exit code.
> > Any other idea how I can get a signal when the app is killed?
>
> You can't. Force stop kills the app, all of its processes, everything
> running inside of those processes, and all resources held by those
> processes. You can't get in the way of this.
Thanks. I must be doing something else wrong then. I load the dll
using "static { System.loadLibrary("einstein"); }". Then in
"onCreate", I call the library, and before I return, I start a
pthread. I would expect that killing the process would also kill all
child processes - including the native ones - but neither on the
emulator nor on the device this is the case. The thread continues
happily, keeping all the resources that were allocated from within the
native library. And since it does not know that the parent process is
gone, it will eat resources. I have not checked yet if another launch
of the app will create another instance of the dll, but that would be
bad.
> You don't need to decrement a usage counter of a linked library. The entire
> processes is being killed.
But that does not kill the dll ("shared library" would be the Unix
term, I had that wrong earlier). I was expecting that at least "void
JNI_OnUnload(JavaVM* vm, void* reserved);" gets called when the parent
process is killed.
I will first try to create a Java thread and use that to kick of the
native thread and see if that fixes things.
If not, I will probably have to add some dead-man timer.
Thanks,
Matthias