0

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?

Arya
  • 8,473
  • 27
  • 105
  • 175

2 Answers2

1

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")
ToasteR
  • 886
  • 7
  • 20
  • The `taskkill` isn't cross platform compatible. – TameHog Apr 17 '15 at 19:09
  • True, but `rt.exec("C:\\Program Files\\Android\\android-sdk\\platform-tools\\adb shell svc data disable");` isn't either. – ToasteR Apr 17 '15 at 19:10
  • `taskkill` is a DOS command that can be run from DOS Command prompt like so to kill all instances of the executable adb.exe like so: `taskkill /F /IM adb.exe`, where `/F` means to kill forcefully and `/IM ...` specifies the image name. Surely there's a similar command with similar syntax in Linux or whatever. – DSlomer64 Oct 14 '18 at 22:58
0

You can kill the process by doing pr.destroy() to kill. But you should listen for the update that comes out, and once it prints what you are looking for, then you should kill it. A way to get the output is here.

Community
  • 1
  • 1
TameHog
  • 950
  • 11
  • 23