I am executing shell commands in code which does a specific job in background. It can last anywhere from 1 - 100 secs.
Ex : adb shell sleep 100
How do I terminate execution of executed commands programmatically, similar to pressing CTRL+C
in PC.
What have I tried :
Initiate
Process mPrcs = Runtime.getRuntime().exec(SUPER_USER);
DataOutputStream sOutputStream = null;
sOutputStream = new DataOutputStream(mPrcs.getOutputStream());
On Start
public void StartClicked(View v)
{
sOutputStream.writeBytes("adb shell sleep 100\n");
sOutputStream.flush();
}
On Stop, execute exit
sOutputStream.writeBytes("exit\n");
sOutputStream.flush();
Destroy()
mPrcs.destroy();
KillProcess using PID, app get's killed but the executed code doesn't stop executing.
None of the above seems to stop.
Also is there a way to find when executed code is completed?
Process.waitfor()
makes my app to hang & goes to not responding state.