简体   繁体   中英

How to know when a process exited?

I have a process that outputs log. But that process exited in Samsung device sometimes. I want to recreate process if that process exited. I can check whether process exited or not by using following code.

if (process.toString().contains("hasExited=true, exitcode=1")) {
    // recreate process
}

Now I want to know is that is there any callback function that are called when process exited. Thanks in advance.

If the Process exits I think it's caused by the System due to low memory/resources (or due to inactivity in some situations). Does the Process belongs the same App you're creating as a Monitor for that process, or it's a different APK? There isn't any callback/event if a process exits due to a Kill() command by the System, so if the Process is yours you could create a one-way continously communication between the Process and your Monitor-App. In this way when the Monitor-App doesn't receive any data from that Process it should consider as killed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM