How to kill all running applications in android?

后端 未结 4 553
情深已故
情深已故 2020-11-30 01:24

I want to kill all running applications in android .so for this task , i implemented following code. But it is not working .App still remains in running.

Act         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 01:58

    You have another possibility if the device is rooted (has superuser rights).

    You can invoke an external process that would use the su rights. But note that it's probably a bad design as Android OS should be the only one to kill processes.

    try {
       Process rootProcess = Runtime.getRuntime().exec(new String[] { "su" });
    
       String command = "kill - 9 ";
    
       BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(rootProcess.getOutputStream()), 2048);
       try {
          bw.write(command);
          bw.newLine();
          bw.flush();
       } catch (IOException e) {
        // Handle error
       }
    } catch (Exception e) {
       e.printStackTrace();
       // Device not rooted!            
    }
    

提交回复
热议问题