Search code examples
javaandroidadb

process continues to run after using Java exec


I have the following method

public static void disableMobileDate()
{
    try
    {
        Runtime rt = Runtime.getRuntime();
        Process pr = null;
        pr = rt.exec("C:\\Program Files\\Android\\android-sdk\\platform-tools\\adb shell svc data disable");
        System.out.println("### Data disabled on mobile device! ###");
    }
    catch (Exception e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Every time this method is ran from my program, it creates a adb.exe in task manager. The adb.exes (multiple adb.exe processes) stays there until I close my program. Is there anyway to make the process end after the command has been successfully executed?


Solution

  • You can call pr.destroy() after your command execution.

    Or you can kill the process via the taskkill command:

    rt.exec("taskkill /F /IM adb.exe")