Android: How to receive process signals in an activity to kill child process?
My application calls Runtime.exec() to launch an executable in a separate process at start up time. I would like this child process to get killed when the parent activity exits. Now I can use onDestroy() to handle regular cases, but not "Force quit", shutdowns from DDMS, or kill from the console since those don't run onDestroy(). The addShutdo开发者_开发百科wnHandler() does not seem to be invoked in these cases either.
Is there any other hook or signal handler that informs my activity that it's about to get terminated ? As an alternative is there a way to have the system automatically kill the child process when the parent dies ?
int main() {
// Spawn a new thread here to do your work
start_thread();
char dummy[10];
gets(dummy);
// When parent dies we reach this line, before that process is blocked in gets line above
return 0;
}
精彩评论