2

i don't know why the Runtime.getRuntime().exec("kill -9"+PID) won't work, but with the adb.exe shell it works perfectly ...!

OnClickListener killButtonListner = new View.OnClickListener() {
        public void onClick(View v) {
            try {
                Process ps = Runtime.getRuntime().exec("kill -9 " + PID);
                Toast.makeText(getBaseContext(),"Process killed" , Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                         Toast.makeText(getBaseContext(),e.getMessage().toString(),Toast.LENGTH_SHORT).show();
            }
        }
    };
    killButton.setOnClickListener(killButtonListner);
}
Bouhirmani
  • 101
  • 1
  • 9

1 Answers1

0

Why don't you use:

Process.killProcess(int pid)

to keep it as Android code, without shelling out? This will be more reliable.

Nova Entropy
  • 5,727
  • 1
  • 19
  • 32
  • I try it but it doesn't work! well, in my application I get all the processes that have the PPID equals to ZYGOTE PID. i add them to a ListView wich allows me to click on the process i want to kill. Here is my code below – Bouhirmani Nov 26 '14 at 17:32