views:

259

answers:

2

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 addShutdownHandler() 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 ?

A: 

Could you post a code snippet of what you did to accomplish this i.e. "blocking read which gets interrupted..." I'm a bit confused on how to do this.

Robert
A: 
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;
}
Cross_